This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class CreateUserService { | |
| public static createUser (name: string) : User{ | |
| if (name === undefined || name === null || name.length <= 2 || name.length > 100) { | |
| throw new Error('User must be greater than 2 chars and less than 100.') | |
| } else { | |
| return new User(name) | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class EditUserService { | |
| public static editUserName (user: User, name: string) : void { | |
| if (name === undefined || name === null || name.length <= 2 || name.length > 100) { | |
| throw new Error('User must be greater than 2 chars and less than 100.') | |
| } else { | |
| user.name = name; | |
| // save | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| interface IName { | |
| value: string | |
| } | |
| class Name extends ValueObject<IName> { | |
| private constuctor (props: IName) { | |
| super(props); | |
| } | |
| public static create (name: string) : Name { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| interface IUser { | |
| readonly name: Name; | |
| } | |
| class User extends Entity<IUser> { | |
| public readonly name: Name; | |
| private constructor (props: IUser) { | |
| super(props); | |
| this.name = props.name; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { shallowEqual } from "shallow-equal-object"; | |
| interface ValueObjectProps { | |
| [index: string]: any; | |
| } | |
| /** | |
| * @desc ValueObjects are objects that we determine their | |
| * equality through their structrual property. | |
| */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| interface IPokemonProps { | |
| name: string; | |
| color: string; | |
| } | |
| abstract class Pokemon implements IPokemonProps { | |
| public name: string; | |
| public color: string; | |
| constructor (props: IPokemonProps) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Pikachu extends Pokemon { | |
| private cat: TapedItem<Battery[], Cat>; | |
| constructor (cat: TapedItem<Battery[], Cat>) { | |
| super({ name: 'Pikachu', color: 'yellow' }); | |
| this.cat = cat; | |
| } | |
| attack () : ZapAttack { | |
| return this.cat.zapAttack(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const pikachu: Pikachu = PikachuFactory.create(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const charmander: Charmander = CharmanderFactory.create(); | |
| const bulbasaur: Bulbasaur = BulbasaurFactory.create(); | |
| const porygon: Porygon = PorygonFactory.create(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { Charmander } from 'pokemon/charmander' | |
| import { CharmanderFactory } from 'pokemon/charmander/factory' | |
| import { Bulbasaur } from 'pokemon/bulbasaur' | |
| import { BulbasaurFactory } from 'pokemon/bulbasaur/factory' | |
| import { Porygon } from 'pokemon/porygon' | |
| import { PorygonFactory } from 'pokemon/porygon/factory' | |
| const charmander: Charmander = CharmanderFactory.create(); | |
| const bulbasaur: Bulbasaur = BulbasaurFactory.create(); | |
| const porygon: Porygon = PorygonFactory.create(); |