Looking for a real-world example illustrating that composition can be superior to inheritance [closed]
Closed 9 years ago.
Why does Java allow to implement different interfaces, each containing a method with the same signature?
I recently found out that I can have two interfaces, one containing a method with the same signature as a method in the other interface. And I can have an interface or class that implements both of afore-mentioned interfaces. So the descendant class/interface implicitly implements two different methods as one method.
LSP vs OCP / Liskov Substitution VS Open Close
I am trying to understand the SOLID principles of OOP and I’ve come to the conclusion that LSP and OCP have some similarities (if not to say more).
How to share common methods if objects have different roles?
If 2 classes have the following in common:
Many small classes vs. logical (but) intricate inheritance
I’m wondering what is better in terms of good OOP desing, clean code, flexibility and avoiding code smells in the future. Image situation, where you have a lot of very similar objects you need to represent as classes. These classes are without any specific functionality, just data classes and are different just by name (and context) Example:
How does strengthening of preconditions and weakening of postconditions violate Liskov substitution principle?
I read that Liskov’s substitution principle is violated if :
Template method within one class without subclasses or inheritance
I have an algorithm with mostly invariant parts that needs to be reused within one class so as to stay DRY.
Code reuse via inheritance [duplicate]
This question already has answers here: Code Smell: Inheritance Abuse [duplicate] (9 answers) Closed 11 years ago. I have a set of classes that are all dealing with some related tasks. These tasks do have different inputs and outputs. This causes it to become impossible to have the tasks done via shared code without having […]
Should I test inherited methods?
Suppose I have a class Manager derived from a base class Employee, and that Employee has a method getEmail() that is inherited by Manager. Should I test that the behaviour of a manager’s getEmail() method is in fact the same as an employee’s?
How often is Inheritance used?
I admit that I am a junior developer, and so far I’ve only built simple web applications in ASP.NET MVC. But I’ve never had to use the inheritance aspect of Object Oriented Programming in my own classes! It is true that in using ASP.NET MVC I inadvertently use inheritance (any controller I create will inherit from the base controller class), but I am referring here to the conscious use of inheritance in my design of a particular web system.