Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The Gang of Four suggests a few strategies for creating good object-oriented des

ID: 3626467 • Letter: T

Question

The Gang of Four suggests a few strategies for creating good object-oriented designs. In particular, they suggest the following:

Design to interfaces.

Favor aggregation over inheritance.

Find what varies and encapsulate it.

Write a report of not more than 5 pages covering the kind of problems the above strategies can solve and how these can be implemented. Elaborate with the help of examples where appropriate.

The report should be written in an approprite font-size (Time New Roman 12 pt, Verdana 10 pt).

Explanation / Answer

To implement this interface, it is necessary to use the implements keyword in the class declaration and the name of the class would change.

If, new class is more or less as the original class. Use inheritance. The new class is now a subclass of the original class. And if the new class must have the original class. Use aggregation. The new class has now the original class as a member.

If it is needed a class 'Cat', that needs 'Eat', 'Walk', 'Purr', and 'Play'. So first try to extend it from a Dog

Here, cat can Bark. And a barking cat violates the principles of the universe. So we need to override the Bark method so that it does nothing.

At this situation even though it is good, it is necessary to use aggregation. Because, cat has an internal dog that wants out.

Aggregation code:

It is one of the Important Encapsulation Principle. For this, it is necessary to take some considerations like,

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote