# Interface and classes

**URL:** <https://discourse.processing.org/t/interface-and-classes/7331>\
**Category:** Coding Questions\
**Created:** [January 8, 2019, 8:50pm UTC](https://discourse.processing.org/t/interface-and-classes/7331 "2019-01-08T20:50:19Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)\
**Post date:** [January 10, 2019, 4:46am UTC](https://discourse.processing.org/t/interface-and-classes/7331/3 "2019-01-10T04:46:38Z")

</div>

> [@bask185](#):
>
> If I add a function to the interface. All other classed need to have this function. That means that if i want to add one specific function to one class. I am forced to add dummy functions to all other classes as well

Yes, you need to avoid adding dummy functions. This just make your code hard to maintain and inefficient. Have a look at this documentation as I think it should give you an idea of how you could use interfaces in your case: [https://docs.oracle.com/javase/tutorial/java/IandI/interfaceAsType.html](https://docs.oracle.com/javase/tutorial/java/IandI/interfaceAsType.html)

Notice that all classes in Java inherits from the Object class, so you could have a container of Objects like this:

`ArrayList objectList = new ArrayList();`

And it should hold any of your instantiated objects. It becomes more tedious if you want to invoke functions defined in derived classes of these objects. To do this would require to do type casting. You might need to do this when using interfaces. There are some user cases that you can avoid this type casting but all boils down to your design. Maybe you should discuss a bit more about:

1. Why you should interfaces
2. Example code of what you are trying to implement. No need to provide full code, but better to provide a small sample showing the backbone and all the good stuff.

Finally, I checked an there are some previous posts similar to yours. For instance: [https://discourse.processing.org/t/looping-different-class-instances/5843/10](https://discourse.processing.org/t/looping-different-class-instances/5843/10) It is a good idea to have a look at some of them. If something is not clear, you can cross-posted here and ask for further clarification.

Kf

---

_[View the full topic](https://discourse.processing.org/t/interface-and-classes/7331)._
