I've noticed that I often write a entity like following:
export class HatebuIdentifier extends Identifier < string > { }
export interface HatebuProps {
readonly id : HatebuIdentifier ;
readonly bookmark : Bookmark ;
}
export class Hatebu extends Entity < HatebuIdentifier > implements HatebuProps {
readonly bookmark : Bookmark ;
constructor ( args : HatebuProps ) {
super ( args . id ) ;
this . bookmark = args . bookmark ;
}
get name ( ) {
return this . id . toValue ( ) ;
}
addBookmarkItems ( bookmarkItems : BookmarkItem [ ] ) {
return new Hatebu ( {
...( this as HatebuProps ) ,
bookmark : this . bookmark . addBookmarkItems ( bookmarkItems )
} ) ;
}
updateBookmarkItems ( bookmarkItems : BookmarkItem [ ] ) {
return new Hatebu ( {
...( this as HatebuProps ) ,
bookmark : this . bookmark . updateBookmarkItems ( bookmarkItems )
} ) ;
}
}
This Hatebu entity has id and Props type.
We can use Props type insteadof Id.
Becaseue, Alwasys Props includes id.
Props
We can realize mixin meaningful mixin #5
Copyable insterface just use Props type
Cons
id is fixed name
Always arguments is object
I've noticed that I often write a entity like following:
This
Hatebuentity has id and Props type.We can use
Propstype insteadofId.Becaseue, Alwasys
Propsincludesid.Props
Copyableinsterface just usePropstypeCons
idis fixed name