What’s an ABSTRACT CLASS?
Similar to interfaces but cannot be instantiated, and are frequently either partially implemented, or not at all implemented.
Different from interface in that:
Similar to interfaces but cannot be instantiated, and are frequently either partially implemented, or not at all implemented.
Different from interface in that:
- A class can inherit from only one abstract class but can implement an unlimited number of interfaces.
- Abstract classes DO contain code & data.
- You can specify methods as ‘virtual’ to force derived classes to create its own implementation.
- Duplication of code. So, code maintainability will be big issue.
- With implementation of concrete (non-abstract) BASE CLASS, developer can instantiate and use the base class as actual classes, which is not intended to do.
So, in short, we should create an ABSTRACT CLASS,
- When want to move the common functionality of 2 or more related classes into a base class and
- When we don't want the base class to be instantiated.
No comments:
Post a Comment