Login :
Password :

Design patterns

Réduction du nombre de méthodes

Problem wording :

Design a system to ensure the comparison (<,>,<=,>=,=) between objects of the same type, whatever the type, even unknown.

Optimal solution :

Static diagram :

Static diagram

The Comparable class offers a structure allowing you to only have to redefine two methods to ensure the comparison between two identical types. Inheritance allows you to add types without ever modifying the existing code.

Les têtes de mule
Cédric BOUHOURS
Cédric BOUHOURS
Cédric BOUHOURS