Skip to content

Instantly share code, notes, and snippets.

@wtrocki
Last active May 23, 2017 17:15
Show Gist options
  • Save wtrocki/eedb276b21308e4e6b1bf8576e94385f to your computer and use it in GitHub Desktop.
Save wtrocki/eedb276b21308e4e6b1bf8576e94385f to your computer and use it in GitHub Desktop.
// OUR CODE
interface Workorder {
field: string
}
interface WorkorderService {
create(workorder: Workorder):void
}
// TODO implementation
// Customer code
interface MyWorkorder extends Workorder{
myfield: string
}
interface MyWorkorderService extends WorkorderService{
// This creates new method
//create(workorder: MyWorkorder): void
// This overrides method
create(workorder: Workorder): void
}
class MyWorkorderServiceImpl implements MyWorkorderService {
create(workorder: MyWorkorder){
workorder.myfield = "test";
}
// This overrides method but myfield is not visible.
// create(workorder: Workorder){
// workorder.myfield
// }
}
// Solution 1 (composition)
class MyWorkorderServiceImpl {
lowLevelService: MyWorkorderService;
constructor(lowLevelService: MyWorkorderService){
this.lowLevelService = lowLevelService;
}
create(workorder: MyWorkorder){
workorder.myfield = "test";
this.lowLevelService.create(workorder);
}
// This overrides method
// create(workorder: Workorder){
// workorder.myfield
// }
}
// Solution 3
// Proper abstraction level and no business logic in API.
// Extending by providing level of abstraction
// Example
class Step{
preAction?: function
postAction?: function
}
const workflow = new Workflow();
workflow.setStepsStrategy(const.LinearStepsStragegy);
Steps[] steps = { SimpleStep, PersistenStep, FormsStep, RemoteDataStep }
steps[0].setMetadata({field:{name: "test"}});
workflow.assignSteps(steps);
// Documentation for each of this interfaces rather than only MODULE interfaces.
// Aproach similar to https://www.optaplanner.org/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment