File tree 1 file changed +12
-18
lines changed
1 file changed +12
-18
lines changed Original file line number Diff line number Diff line change @@ -16,39 +16,33 @@ interface Animal {
16
16
}
17
17
18
18
class Sheep implements Animal {
19
- private name : string ;
19
+ name : string ;
20
20
21
21
public constructor ( ) {
22
22
console . log ( "Sheep is made" ) ;
23
23
}
24
24
25
- public makeCopy ( ) : Animal {
25
+ makeCopy ( ) : Animal {
26
26
console . log ( "Sheep is being made" ) ;
27
27
const sheepObject : Sheep = Object . create ( this ) ;
28
28
return sheepObject ;
29
29
}
30
-
31
- public setName ( name : string ) : void {
32
- this . name = name ;
33
- }
34
-
35
- public getName ( ) : string {
36
- return this . name ;
37
- }
38
30
}
39
31
40
32
class CloneFactory {
41
- public getClone ( animalSample : Animal ) : Animal {
33
+ getClone ( animalSample : Animal ) : Animal {
42
34
return animalSample . makeCopy ( ) ;
43
35
}
44
36
}
45
37
46
38
//-------------------------------------------------
47
39
48
- const animalMaker : CloneFactory = new CloneFactory ( ) ;
49
- const sally : Sheep = new Sheep ( ) ;
50
- sally . setName ( "sally" ) ;
51
- const clonedSheep : Sheep = < Sheep > animalMaker . getClone ( sally ) ;
52
- clonedSheep . setName ( "sally clone" ) ;
53
- console . log ( sally . getName ( ) ) ;
54
- console . log ( clonedSheep . getName ( ) ) ;
40
+ const animalMaker = new CloneFactory ( ) ;
41
+ const sally = new Sheep ( ) ;
42
+ sally . name = "sally" ;
43
+
44
+ const clonedSheep = < Sheep > animalMaker . getClone ( sally ) ;
45
+ clonedSheep . name = "sally clone" ;
46
+
47
+ console . log ( sally . name ) ;
48
+ console . log ( clonedSheep . name ) ;
You can’t perform that action at this time.
0 commit comments