Sign in
Log inSign up
clean code
clean code
#clean-code
183 followers·902 articles
Popular this week 🔥
Dominic Duke
Okosun Mary
Eleftheria Batsou
Manthankumar Satani
Okosun Mary and 16 others are discussing this17 people are discussing this
Musa Wenkosi Biyela
This article has helped me,Now I know what to do as a beginner in coding. Thank You!
5
Discuss

·

171 likes

·

7.5K reads

raddevus
That's a nice well-written article with good points. Software Dev Team Lead Here's a Software Dev Team Lead's way of doing this: No need to even determine the type. Instead the type implements the correct method for itself & there is never a need to even know the base type. Strategy pattern. 😎🤓 Try The Code Try the code out and see it run at: https://stackblitz.com/edit/typescript-xibe8j?file=index.ts interface Animal{ Speak(); } class Cat implements Animal{ Speak(){ alert("meow"); } } class Dog implements Animal{ Speak(){ alert("woof"); } } class Lion implements Animal{ Speak(){ alert("roar!"); } } let a : Animal = new Dog(); a.Speak(); // woof let allAnimals = []; allAnimals.push(new Dog()); allAnimals.push(new Lion()); allAnimals.push(new Cat()); allAnimals.push(new Lion()); allAnimals.forEach( a => a.Speak());
9