Advertisement
Guest User

Untitled

a guest
Apr 8th, 2020
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. class Czlowiek {
  3.  
  4.     constructor(imie, nazwisko){
  5.         if(typeof(imie) !== "string")
  6.             throw "imie != string";
  7.         if(typeof(nazwisko) !== "string")
  8.             throw "nazwisko != string";
  9.         this._imie = imie;
  10.         this._nazwisko = nazwisko;
  11.     }
  12.  
  13.     get imie(){
  14.         return this._imie;
  15.     }
  16.  
  17.     get nazwisko(){
  18.         return this._nazwisko;
  19.     }
  20.  
  21. }
  22.  
  23. class Klient extends Czlowiek {
  24.  
  25.     static stworzKlienta(czlowiek, id, adres, dataUrodzenia, dataWaznosciKarnetu, telefon) {
  26.         return new Klient(czlowiek.imie, czlowiek.nazwisko, id, adres, dataUrodzenia, dataWaznosciKarnetu, telefon)
  27.     }
  28.  
  29.     constructor(imie, nazwisko, id, adres, dataUrodzenia, dataWaznosciKarnetu, telefon){
  30.         super(imie, nazwisko);
  31.         if(typeof(id) !== "number")
  32.             throw "id != number";
  33.         if(!(dataUrodzenia instanceof Date))
  34.             throw "dataUrodzenia != Date";
  35.         this.adres = adres;
  36.         this.dataWaznosciKarnetu = dataWaznosciKarnetu;
  37.         this.telefon = telefon;
  38.         this._id = id;
  39.         this._adres = adres;
  40.         this._dataUrodzenia = dataUrodzenia;
  41.         this._dataWaznosciKarnetu = dataWaznosciKarnetu;
  42.         this._telefon = telefon;
  43.     }
  44.  
  45.     get id() {
  46.         return this._id;
  47.     }
  48.  
  49.     get adres() {
  50.         return this._adres;
  51.     }
  52.  
  53.     get dataUrodzenia() {
  54.         return this._dataUrodzenia;
  55.     }
  56.  
  57.     get dataWaznosciKarnetu() {
  58.         return this._dataWaznosciKarnetu;
  59.     }
  60.  
  61.     get telefon() {
  62.         return this._telefon;
  63.     }
  64.  
  65.     set adres(value) {
  66.         if(typeof(value) !== "string")
  67.             throw "adres != string";
  68.         this._adres = value;
  69.     }
  70.  
  71.     set dataWaznosciKarnetu(value) {
  72.         if(!(value instanceof Date))
  73.             throw "value != Date";
  74.         this._dataWaznosciKarnetu = value;
  75.     }
  76.  
  77.     set telefon(value) {
  78.         if(typeof(value) !== "string")
  79.             throw "value != string";
  80.         this._telefon = value;
  81.     }
  82.  
  83. }
  84.  
  85. function test() {
  86.     let czlowiek = new Czlowiek("Jan", "Kowalski");
  87.     console.log("człowiek", czlowiek);
  88.     let nowyKlient = Klient.stworzKlienta(czlowiek, 1,"Warszawa", new Date("1990-04-10"), new Date("2020-12-10"), "+48 123 456 789");
  89.     console.log("klient", nowyKlient);
  90. }
  91.  
  92. test();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement