---
title: "Comment by raddevus on \"How to code like a pro in 2022 and avoid If-Else\" | Hashnode"
description: "That&#39;s a nice well-written article with good points. Software Dev Team Lead Here&#39;s a Software Dev Team Lead&#39;s way of doing this: No need to even det"
url: "https://hashnode.com/posts/how-to-code-like-a-pro-in-2022-and-avoid-if-else/62aab3692b2b09182b654c62/comment/62b601d392447c9aed5b5ddb"
---

[Discussion](https://hashnode.com/posts/how-to-code-like-a-pro-in-2022-and-avoid-if-else/62aab3692b2b09182b654c62)

Comment [How to code like a pro in 2022 and avoid If-Else](https://hashnode.com/posts/how-to-code-like-a-pro-in-2022-and-avoid-if-else/62aab3692b2b09182b654c62)

[raddevus](https://hashnode.com/@raddevus)

[Jun 24, 2022](https://hashnode.com/posts/how-to-code-like-a-pro-in-2022-and-avoid-if-else/62aab3692b2b09182b654c62/comment/62b601d392447c9aed5b5ddb)

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: [stackblitz.com/edit/typescript-xibe8j](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());
```

[Thai Tran](https://hashnode.com/@thaitran)

[Jun 24, 2022](https://hashnode.com/posts/how-to-code-like-a-pro-in-2022-and-avoid-if-else/62aab3692b2b09182b654c62/comment/62b601d392447c9aed5b5ddb#reply-62b630f892447c9aed5b6259)

Take my 💰 please!

[Alessandro](https://hashnode.com/@anger)

[Jul 2, 2022](https://hashnode.com/posts/how-to-code-like-a-pro-in-2022-and-avoid-if-else/62aab3692b2b09182b654c62/comment/62b601d392447c9aed5b5ddb#reply-62c06ca6ccecfb25bbc73a75)

This is good, but you can run into abstraction issues (I am not familiar with Typescript, but on this I am coming from a C++ point of view)... and the article makes such a good way to evolve this if/else with pushing it further to call functions from a map.
