
Episode 9 · Season 14
Interfaces - An Object-Oriented Contract For Usage
About this episode
This episode, we look at interfaces. These are not supported by all languages. However, when they are supported, they are very useful. The interface specification allows us to provide language-based constraints for our method signatures. It also is an excellent way to enforce consistancy.
Interfaces As A Tool For Consistancy
The most important result of using interfaces is that they enforce a consistant way to communicate with developers. Any class that uses one of these items will be forced to comply with the defined signatures. The language compiler or validations will let the developer know when they are not following the rules. While there might be empty methods allowed, the developer must specifically handle the method and return an empty result.
Common Examples
The typical methods and functions we have mentioened throughout this season are going to often end up in an interface. We see this in frameworks where there are numerous helper objects in the system. For example, there may be interfaces to save, print, load, export, or compare instances. These consistant interfaces allow us to treat a broad range of disparate objects the same.
One such example would be sorting a list. We all can imagine sorting a list of names. On the other hand, how would we sort a list of cars? We can implement a compare interface in the car class. That can provide a process for comparing two cars and deciding an order to them. Once that has been implemented, we can display a list of cars and provide a sort option.
More from Develpreneur: Become a Better Developer and Entrepreneur
A handful of people love your MVP. Their suggestions keep coming, and AI helps you turn those requests into working features quickly. The product is growing. Whether it is growing in the right directi…
Your team can generate an interface faster than ever. Meanwhile, customers are still staring at confusing error messages, waiting for pages to load, and trying to figure out what happens after they cl…
After a year of deadlines, long hours, and projects that seemed determined to last forever, Thanksgiving offers a chance to pause and enjoy what all that effort has made possible. In this Thanksgiving…
The holiday is almost here, but your brain is still at work. There is something to finish, something to check, and probably something you could squeeze in before everyone arrives. Closing the laptop s…
Building a successful business requires more than developing a great product. As companies grow, they face new challenges involving customer expectations, operational efficiency, financial decisions,…