some challenges. We cannot make this code reusable for other classes or objects. The class has a whole lot of logic interconnected that we would have a hard time fi xing errors. And as the codebase grows, so does the logic, making it even harder to understand what is going on.
easier to understand as each core functionality has its own class. We can test for errors more ef fi ciently . The code is now reusable. Before, we could only use these functionalities inside one class but now they can be used in any class .
for extension, but closed for modi fi cation. This implies that such entities – classes, functions, and so on – should be created in a way that their core functionalities can be extended to other entities without altering the initial entity's source code .
fi cient. We modify the code constantly which may lead to bugs. And the code only has provision for humans. What if we have to calculate for an animal or an object?
Haider implements Entity { int height; int weight; public double CalculateBMI() { return Haider.height/Haider.weight; } } public class Saleem implements Entity { int height; int weight; public double CalculateBMI() { return Saleem.height/Saleem.weight; } }
of a class is passed/ extended to another class, the inheriting class should have a use case for all the properties and behavior of the inherited class.
} public class Frog extends Amphibian { public void swim() { System.out.println("The frog is swimming"); } public void walk() { System.out.println("The frog is walking on land"); } }
} public class Shark extends Amphibian { public void swim() { System.out.println("The shark is swimming"); } public void walk() { System.out.println("The shark is walking on land"); } }
{ System.out.println("Jane is teaching the students English language."); } @Override public void Biology() { } @Override public void Chemistry() { } @Override public void Mathematics() { } }
{ System.out.println("Jane has started teaching."); } @Override public void English() { System.out.println("Jane is teaching the students English language."); } }
implements ATM { @Override ATM_OPERATION(){ // code to add money to ATM and increase the ATM balance } } public class Customer implements ATM { @Override ATM_OPERATION(){ // code to withdraw money from ATM and decrease the ATM balance } }