This is for JAVA object oriented programming. Suppose that we want to design/imp
ID: 3812352 • Letter: T
Question
This is for JAVA object oriented programming.
Suppose that we want to design/implement a software to manage a factory which manufacture different kind of clothing. Let’s call them fabrics.
We have different kinds of fabrics, some are washable, some are not. Due to the advancement of technology, some non-washable fabric later can be washed by some kind of high tech washers. For example, DryWasher.
Explain how we can borrow the ideas of Java’s design of Object, Comparable and Comparator to design our software. To be specific, explain what classes and interfaces we would like to have for our design, supposing that we have two kind of concrete fabrics: FabricA (which is washable) and FabricB(which is not washable, but it can be washed by some kind of FabricBWasher).
Explanation / Answer
Comparable and Comparator are two interfaces provided by Java Core API.
Comparable is implemented by a class in order to be able to comparing object of itself with some other objects. The class itself must implement the interface in order to be able to compare its instance(s). The method required for implementation is compareTo().
Comparator can be used if you want to compare objects based on certain attributes/fields. For example, 2 persons can be compared based on `height` or `age` etc. (this can not be done using comparable.).The method required to implement is compare().
So in this way to compare FabricA with FabricB on basis of washable and nonwashable, we will use Compartor interface and to Comparable interface for clothes that can be washed by FabricBWasher.
For our design
1.Comparable Interface
2.Comparator Interface
3.class that implements interface
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.