Skip to content

Instantly share code, notes, and snippets.

@achimoraites
Created June 25, 2018 06:27
Show Gist options
  • Save achimoraites/58f139b2d7515fa9e43588da46b6106b to your computer and use it in GitHub Desktop.
Save achimoraites/58f139b2d7515fa9e43588da46b6106b to your computer and use it in GitHub Desktop.
Cohesion Types
class Example {
private ss: string;
constructor(s:string){
this.ss = s;
}
// Functional Cohesion
parseString(s: string): string {
this.ss = s + "...";
return this.ss;
}
// Sequential Cohesion
readString(s: string) {
let parsed = this.parseString(s);
let isValidated = this.validateString(parsed);
if(isValidated){
console.log(parsed);
}
}
// Communicational / Informational Cohesion
validateString(s: string): boolean {
if (s.endsWith("...")) {
return this.executeFoo(s);
} else {
// do something else
return this.executeNonFoo(s);
}
}
// Procedural Cohesion
resetString(){
// check if valid
let valid = this.validateString(this.ss);
if(valid){
this.ss.replace("...","");
}
}
// "Helpers"
executeFoo(s:string):boolean{
return true;
}
executeNonFoo(s:string):boolean{
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment