I have been programming for decades but I have not been used to object oriented programming. But for recenet years, I had a great opportunity to learn OOP, its principles, and a lot of patterns that are great.
Since I’ve learned OOP, I tried to apply them to a couple of projects and found those projects successful. Unfortunately I didn’t follow extreme programming that suggests writing test first, mainly because their time frame were tight. What I did for those projects were
- Identify all necessary classes and create them with proper properties and methods
- whenever there is dependency between classes, write interface between them
- see if there is any patterns for certain relationships between classes to replace
By successful, I meant that it was quick development effort, the classes can be reused better, and flexible enough so that another programmer does not have to change something else to fix another part.
But I wonder if this is a good practice. Of course, I know I need to put writing unit tests first in my work process. But other than that, is there any problem with this approach – creating lots of interfaces – in long term?
6
Yes .. Using interfaces in Object Oriented Programming would be good practice. Benefits of using interfaces in your model :
- Interfaces provides asynchronous development without defining Class implementations.
- Multiple class implementations of a particular behavior/operation.
- Interfaces provides a defined set of standards that must be followed by implementation classes.
- If you are writing a API a utility package you must expose the operations using interfaces so that a user of that API can easily integrate.
These features pointed above are automatically included with your model in case of using interfaces but in case of direct class implementations you need to take care of these manually.
However there are some disadvantages also :
- New development members needs to follow the standards defined by interfaces if they are developing new implementations. It is bit complicated and takes time to develop code by new members.
- In case of changing the interface standards we need to change into all the class implementations as well.
5