File tree Expand file tree Collapse file tree 4 files changed +57
-3
lines changed Expand file tree Collapse file tree 4 files changed +57
-3
lines changed Original file line number Diff line number Diff line change
1
+ import { Toy } from './toy.model' ;
2
+ import { Cat } from './cat.model' ;
3
+
4
+ export class CatAdapter implements Toy {
5
+ private cat : Cat ;
6
+
7
+ constructor ( cat : Cat ) {
8
+ this . cat = cat ;
9
+ }
10
+
11
+ public squeak ( ) : string {
12
+ return this . cat . makeSound ( ) ;
13
+ }
14
+ }
Original file line number Diff line number Diff line change
1
+ export interface Cat {
2
+ hunt ( ) : string ;
3
+ makeSound ( ) : string ;
4
+ }
5
+
6
+ // adaptee
7
+ export class BritishShortHair implements Cat {
8
+ public hunt ( ) : string {
9
+ return 'Hunting birds..' ;
10
+ }
11
+
12
+ public makeSound ( ) : string {
13
+ return 'Miau.. Miau..' ;
14
+ }
15
+ }
16
+
17
+ export class NorwegianForest implements Cat {
18
+ public hunt ( ) : string {
19
+ return 'Hunting fish..' ;
20
+ }
21
+
22
+ public makeSound ( ) : string {
23
+ return 'Rrrroar.. Rrrroar..' ;
24
+ }
25
+ }
Original file line number Diff line number Diff line change
1
+ // target interface - toys dont hunt and only squeak
2
+ export interface Toy {
3
+ squeak ( ) : string ;
4
+ }
5
+
6
+ export class ToyCat implements Toy {
7
+ public squeak ( ) : string {
8
+ return 'squeaaaaaak...' ;
9
+ }
10
+ }
Original file line number Diff line number Diff line change @@ -14,11 +14,16 @@ const routes: Routes = [
14
14
path : 'prototype' ,
15
15
loadChildren : ( ) => import ( './03. Prototype/prototype.module' ) . then ( m => m . PrototypeModule )
16
16
} ,
17
- { path : 'builder' ,
17
+ {
18
+ path : 'builder' ,
18
19
loadChildren : ( ) => import ( './04. Builder/builder.module' ) . then ( m => m . BuilderModule )
19
20
} ,
20
- { path : 'factory-method' ,
21
- loadChildren : ( ) => import ( './05. Factory Method/factory-method.module' ) . then ( m => m . FactoryMethodModule ) }
21
+ {
22
+ path : 'factory-method' ,
23
+ loadChildren : ( ) => import ( './05. Factory Method/factory-method.module' ) . then ( m => m . FactoryMethodModule ) } ,
24
+ {
25
+ path : 'adapter' ,
26
+ loadChildren : ( ) => import ( './06. Adapter/adapter.module' ) . then ( m => m . AdapterModule ) }
22
27
] ;
23
28
24
29
@NgModule ( {
You can’t perform that action at this time.
0 commit comments