In a previous post; we had learned about abstraction for building powerful software products. Now let us learn about refinement.
Refinement is the opposite concept compared to abstraction. In abstraction, we try to aggregate dissimilar things by ignoring dissimilarities and aggregating them using the common thread running among them. When we are able to aggregate things for the purpose of building a software product which can be used by many types of users; then the next thing we need to do is to actually build different software product features which are useful for these different types of users. How we can do that? Let us learn here.
In the post on abstraction, we had seen how we can aggregate similar functionalities of categorizing text (numbered, tabulated, bulletted etc.) for a word processing software product, using abstraction. Now when we need to implement these functionalities then we need to implement them separately. How we can do that?
At the abstracted level we can create a common interface or class. This class will have the common functionalities implemented. Now we can create child classes which will implement the specific functionalities of each of the software features. For example, we can have a child class which can now implement functionality for formatting text in bullet form and another child class which can now implement functionality for numbered text. This way we can implement all functionalities needed by creating a separate child class for each functionality.
In the old programming languages; refinement used to be done using many if-else statements. The drawback of doing it this way was that you can end up having many nested programming statements. This would lead to unstable behavior of the software product during use and would lead to software defects. Using child classes overcomes this problem. Child classes allow easy maintenance of the software product as well.