Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- abstract class PlantCreator {
- public abstract getInstance(): IPlant;
- public getName(): string {
- const plant = this.getInstance();
- return plant.name;
- }
- public getType(): string {
- const plant = this.getInstance();
- return plant.type;
- }
- }
- interface IPlant {
- name?: string;
- sort?: string;
- type?: string;
- }
- class CannabisFactory extends PlantCreator {
- constructor(
- name: string, sort: string
- ) {
- super();
- this.name = name;
- this.sort = sort;
- }
- private type: string = 'Cannabis';
- private name: string;
- private sort: string;
- public getInstance(): IPlant {
- return new Cannabis(
- this.name, this.sort
- );
- }
- }
- class Cannabis implements IPlant {
- constructor(
- name: string,
- sort: string
- ) { }
- sort: string = this.sort;
- public getSort(): string {
- return this.sort;
- }
- }
- function getNewGanja(ganja: PlantCreator): void {
- console.log(ganja.getName());
- }
- getNewGanja(new CannabisFactory('First', 'WW'));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement