Skip to content

Instantly share code, notes, and snippets.

View stemmlerjs's full-sized avatar

Khalil Stemmler stemmlerjs

View GitHub Profile
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)
}
}
}
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
}
}
}
interface IName {
value: string
}
class Name extends ValueObject<IName> {
private constuctor (props: IName) {
super(props);
}
public static create (name: string) : Name {
interface IUser {
readonly name: Name;
}
class User extends Entity<IUser> {
public readonly name: Name;
private constructor (props: IUser) {
super(props);
this.name = props.name;
import { shallowEqual } from "shallow-equal-object";
interface ValueObjectProps {
[index: string]: any;
}
/**
* @desc ValueObjects are objects that we determine their
* equality through their structrual property.
*/
interface IPokemonProps {
name: string;
color: string;
}
abstract class Pokemon implements IPokemonProps {
public name: string;
public color: string;
constructor (props: IPokemonProps) {
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();
const pikachu: Pikachu = PikachuFactory.create();
const charmander: Charmander = CharmanderFactory.create();
const bulbasaur: Bulbasaur = BulbasaurFactory.create();
const porygon: Porygon = PorygonFactory.create();
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();