+ 1
What is use of abstract methods on Java?
we make an abstract method that don't have any coding then we override it in child class. where is the right use of it? instead we can use normal methods what is problem with that?
2 ответов
+ 1
One practical use is when you have a large developer team, this communicates to the dev how this method/class should be used.
The abstract class might have a key method but no way to know how the implementation will happen. Let's suppose there is some series of business calculations for a variety of products. The abstract class supplies the framework for how the process is executed and finished off/tidied up (like consolidating all the calculations into a summary) but the actual 'calculate' process will depend on a number of things. In this case, we create separate classes that extend this abstract class and implement the abstract 'calculate' method. Then for each class (read: process) we setup (from the base abstract class) calculate (from the concrete class) and tidy up (again from the base).
In this way we haven't duplicated the start and end processes. If our architecture changed the way the process is executed, we change the base but the rest is fine to keep.
+ 1
okay thanks man, this mean if we want our method to be implemented them we make abstract.