Skip to content

Commit 7ba8b99

Browse files
PatrickPatrick
authored andcommitted
feature(): add facade pattern
1 parent 3620710 commit 7ba8b99

File tree

24 files changed

+239
-31
lines changed

24 files changed

+239
-31
lines changed

src/app/01. Abstract Factory/abstract-factory/abstract-factory.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[style.fontFamily]="selectedTheme.getFontName()"
66
>
77
<h1>
8-
Abstract Factory
8+
Abstract Factory Pattern
99
</h1>
1010

1111
<div>

src/app/02. Singleton/singleton/singleton.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
<div class="container">
33
<h1>
4-
Singleton
4+
Singleton Pattern
55
</h1>
66
<div class="description">
77
id stays the same, because we don't create a new instance. If you reload the page, there would be a new instance, because the component (parent of teas) is destroyed and initialized

src/app/03. Prototype/prototype/prototype.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div class="container">
22
<h1>
3-
Prototype
3+
Prototype Pattern
44
</h1>
55
<mat-card>
66
<mat-card-title>

src/app/04. Builder/builder/builder.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div class="container">
22
<h1>
3-
Builder
3+
Builder Pattern
44
</h1>
55
<div class="content">
66
<mat-card *ngFor="let house of houses; index as i">

src/app/05. Factory Method/factory-method/factory-method.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div class="container">
22
<h1>
3-
Factory Method
3+
Factory Method Pattern
44
</h1>
55
<mat-card>
66
<mat-card-title>

src/app/06. Adapter/adapter/adapter.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div class="container">
22
<h1>
3-
Adapter
3+
Adapter Pattern
44
</h1>
55
<div class="content">
66
<mat-card>

src/app/07. Bridge/.gitkeep

Whitespace-only changes.

src/app/08. Composite/.gitkeep

Whitespace-only changes.

src/app/09. Decorator/.gitkeep

Whitespace-only changes.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { NgModule } from '@angular/core';
2+
import { Routes, RouterModule } from '@angular/router';
3+
4+
import { FacadeComponent } from './facade/facade.component';
5+
6+
const routes: Routes = [{ path: '', component: FacadeComponent }];
7+
8+
@NgModule({
9+
imports: [RouterModule.forChild(routes)],
10+
exports: [RouterModule]
11+
})
12+
export class FacadeRoutingModule { }

src/app/10. Facade/facade.module.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { NgModule } from '@angular/core';
2+
import { CommonModule } from '@angular/common';
3+
4+
import { FacadeRoutingModule } from './facade-routing.module';
5+
import { FacadeComponent } from './facade/facade.component';
6+
import {AngularMaterialModule} from "../modules/angular-material.module";
7+
8+
9+
@NgModule({
10+
declarations: [FacadeComponent],
11+
imports: [
12+
CommonModule,
13+
FacadeRoutingModule,
14+
AngularMaterialModule
15+
]
16+
})
17+
export class FacadeModule { }
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<div class="container">
2+
<h1>
3+
Facade Pattern
4+
</h1>
5+
<div class="content">
6+
<mat-card>
7+
<mat-card-title>
8+
Coffee factory log
9+
</mat-card-title>
10+
<mat-card-actions>
11+
<button mat-raised-button (click)="btnProduceCoffee()">Make coffee</button>
12+
</mat-card-actions>
13+
<mat-card-content>
14+
<div *ngFor="let log of logProduction">
15+
{{ log }}
16+
<div>-------</div>
17+
</div>
18+
</mat-card-content>
19+
</mat-card>
20+
</div>
21+
</div>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
div {
2+
text-align: center;
3+
}
4+
5+
div.container {
6+
display: flex;
7+
flex-direction: column;
8+
align-items: center;
9+
}
10+
11+
div.content {
12+
display: flex;
13+
flex-direction: row;
14+
align-items: flex-start;
15+
}
16+
17+
mat-card {
18+
margin: 15px;
19+
max-width: 300px;
20+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { ComponentFixture, TestBed } from '@angular/core/testing';
2+
3+
import { FacadeComponent } from './facade.component';
4+
5+
describe('FacadeComponent', () => {
6+
let component: FacadeComponent;
7+
let fixture: ComponentFixture<FacadeComponent>;
8+
9+
beforeEach(async () => {
10+
await TestBed.configureTestingModule({
11+
declarations: [ FacadeComponent ]
12+
})
13+
.compileComponents();
14+
});
15+
16+
beforeEach(() => {
17+
fixture = TestBed.createComponent(FacadeComponent);
18+
component = fixture.componentInstance;
19+
fixture.detectChanges();
20+
});
21+
22+
it('should create', () => {
23+
expect(component).toBeTruthy();
24+
});
25+
});
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { Component, OnInit } from '@angular/core';
2+
import {CoffeeFacade, Facade} from "../models/facade.model";
3+
4+
@Component({
5+
selector: 'app-facade',
6+
templateUrl: './facade.component.html',
7+
styleUrls: ['./facade.component.scss']
8+
})
9+
export class FacadeComponent implements OnInit {
10+
public logProduction: string[];
11+
private facade: Facade;
12+
13+
constructor() {
14+
this.facade = new CoffeeFacade();
15+
this.logProduction = new Array<string>();
16+
}
17+
18+
ngOnInit(): void {
19+
}
20+
21+
public btnProduceCoffee() {
22+
const log = this.facade.produce();
23+
console.log(log);
24+
this.logProduction.push(log);
25+
}
26+
27+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export interface Drink {
2+
cook(): string;
3+
}
4+
5+
export class Coffee implements Coffee {
6+
public cook(): string {
7+
return 'cook coffee...';
8+
}
9+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import {CoffeeTrader, Trader} from "./trader.model";
2+
import {CoffeeMill, Mill} from "./mill.model";
3+
import {Coffee, Drink} from "./drink.model";
4+
5+
export interface Facade {
6+
produce(): string;
7+
}
8+
9+
export class CoffeeFacade implements Facade {
10+
protected trader: Trader;
11+
protected mill: Mill;
12+
protected drink: Drink;
13+
14+
constructor(trader: Trader = null,
15+
mill: Mill = null,
16+
drink: Drink = null) {
17+
this.trader = trader || new CoffeeTrader();
18+
this.mill = mill || new CoffeeMill();
19+
this.drink = drink || new Coffee();
20+
}
21+
22+
public produce(): string {
23+
let result = 'Start producing coffee...';
24+
result += this.trader.getCoffee();
25+
result += this.mill.grindCoffee();
26+
result += this.drink.cook();
27+
return result;
28+
}
29+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export interface Mill {
2+
grindCoffee(): string;
3+
}
4+
5+
export class CoffeeMill implements Mill {
6+
public grindCoffee(): string {
7+
return 'grind coffee...';
8+
}
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export interface Trader {
2+
getCoffee(): string;
3+
}
4+
5+
export class CoffeeTrader implements Trader {
6+
public getCoffee() {
7+
return 'get coffee from Brazil..';
8+
}
9+
}

src/app/11. Flyweight/.gitkeep

Whitespace-only changes.

src/app/12. Proxy/.gitkeep

Whitespace-only changes.

src/app/app-routing.module.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import { NgModule } from '@angular/core';
22
import { Routes, RouterModule } from '@angular/router';
33

44
const routes: Routes = [
5+
{
6+
path: 'home',
7+
loadChildren: () => import('./xx. components/Home/home.module').then(m => m.HomeModule)
8+
},
59
{
610
path: 'abstract-factory',
711
loadChildren: () => import('./01. Abstract Factory/abstract-factory.module').then(m => m.AbstractFactoryModule)
@@ -26,10 +30,14 @@ const routes: Routes = [
2630
loadChildren: () => import('./06. Adapter/adapter.module').then(m => m.AdapterModule)
2731
},
2832
{
29-
path: 'home',
30-
loadChildren: () => import('./xx. components/Home/home.module').then(m => m.HomeModule)
33+
path: 'facade',
34+
loadChildren: () => import('./10. Facade/facade.module').then(m => m.FacadeModule)
3135
},
32-
{ path: '', redirectTo: '/home', pathMatch: 'full' }
36+
{
37+
path: '',
38+
redirectTo: '/home', pathMatch: 'full'
39+
}
40+
3341
];
3442

3543
@NgModule({
Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,39 @@
1-
<mat-card>
2-
<mat-card-title>
3-
Creational Pattern
4-
</mat-card-title>
5-
<mat-card-content>
6-
<a mat-raised-button [routerLink]="['/abstract-factory']" routerLinkActive="abstract-factory" color="primary">
7-
Abstract Factory
8-
</a>
9-
<a mat-raised-button [routerLink]="['/factory-method']" routerLinkActive="factory-method" color="primary">
10-
Factory Method
11-
</a>
12-
<a mat-raised-button [routerLink]="['/builder']" routerLinkActive="builder" color="primary">
13-
Builder
14-
</a>
15-
<a mat-raised-button [routerLink]="['/singleton']" routerLinkActive="singleton" color="primary">
16-
Singleton
17-
</a>
18-
<a mat-raised-button [routerLink]="['/prototype']" routerLinkActive="prototype" color="primary">
19-
Prototype
20-
</a>
21-
</mat-card-content>
22-
</mat-card>
1+
<div class="container">
2+
<mat-card>
3+
<mat-card-title>
4+
Creational Patterns
5+
</mat-card-title>
6+
<mat-card-content>
7+
<a mat-raised-button [routerLink]="['/abstract-factory']" routerLinkActive="abstract-factory" color="primary">
8+
Abstract Factory
9+
</a>
10+
<a mat-raised-button [routerLink]="['/factory-method']" routerLinkActive="factory-method" color="primary">
11+
Factory Method
12+
</a>
13+
<a mat-raised-button [routerLink]="['/builder']" routerLinkActive="builder" color="primary">
14+
Builder
15+
</a>
16+
<a mat-raised-button [routerLink]="['/singleton']" routerLinkActive="singleton" color="primary">
17+
Singleton
18+
</a>
19+
<a mat-raised-button [routerLink]="['/prototype']" routerLinkActive="prototype" color="primary">
20+
Prototype
21+
</a>
22+
</mat-card-content>
23+
</mat-card>
24+
25+
<mat-card>
26+
<mat-card-title>
27+
Structural Patterns
28+
</mat-card-title>
29+
<mat-card-content>
30+
<a mat-raised-button [routerLink]="['/adapter']" routerLinkActive="adapter" color="primary">
31+
Adapter
32+
</a>
33+
<a mat-raised-button [routerLink]="['/facade']" routerLinkActive="facade" color="primary">
34+
Facade
35+
</a>
36+
</mat-card-content>
37+
</mat-card>
38+
39+
</div>

src/app/xx. components/Home/home/home.component.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
div.container {
2+
display: flex;
3+
flex-direction: row;
4+
}
15
mat-card {
26
text-align: center;
7+
margin: 15px;
38
}
49

510
mat-card-content {

0 commit comments

Comments
 (0)