# How to determine right Class to use, if not equal to used variable's Class?

**URL:** <https://discourse.processing.org/t/how-to-determine-right-class-to-use-if-not-equal-to-used-variables-class/5940>\
**Category:** Coding Questions\
**Created:** [November 26, 2018, 3:10am UTC](https://discourse.processing.org/t/how-to-determine-right-class-to-use-if-not-equal-to-used-variables-class/5940 "2018-11-26T03:10:35Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![Kevin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kevin/32/2297_2.png) [@Kevin](https://discourse.processing.org/u/Kevin)\
**Post date:** [November 26, 2018, 8:14pm UTC](https://discourse.processing.org/t/how-to-determine-right-class-to-use-if-not-equal-to-used-variables-class/5940/4 "2018-11-26T20:14:56Z")

</div>

Sounds like you might be looking for the [command pattern](https://en.wikipedia.org/wiki/Command_pattern)?

Basically, you’d want to create a top-level interface like this:

```auto
interface FoodAction{
  void act();
}

```

Then you’d create implementations of that interface for each behavior you want to model:

```auto
class Raw implements FoodAction{
  void act(){
    println("is raw");
  }
}

class Cooked implements FoodAction{
  void act(){
    println("is cooked");
  }
}

```

Then you could use instances of `FoodAction` like this:

```auto
class Banana{
  ArrayList<FoodAction> actions = new ArrayList<>();
  
  Banana(ArrayList<FoodAction> actions){
    this.actions = actions;
  }

  void doAllActions(){
    for(FoodAction action : actions){
      action.act();
    }
  }
}

```

There are a bunch of different ways to organize this, but hopefully that shows the general approach.

---

_[View the full topic](https://discourse.processing.org/t/how-to-determine-right-class-to-use-if-not-equal-to-used-variables-class/5940)._
