Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it correct to use Java interfaces to represent nouns AND adjectives?

I'm running into a problem understanding the semantics of Java's interfaces. I am modeling a problem with interfaces before I fill them in with code. I do this by seeking out the nouns in the problem and creating an interface for them, for example:

Every house has at least one person in it. Each house may also contain exactly one bicycle and may contain at least one car.

So, I would create the interfaces IHouse, IPerson, and IVehicle (since we may have different types of houses, peoples, and vehicles in the future).

The problem comes when I get into the adjectives of these nouns, for example:

Each house, bicycle, and car may have a certain color.

Instead of creating the following methods in each vehicle and house class, I create the following interface:

public interface IPainted {

    public Paint getPaint();

    public void setPaint();

}

and apply it to the vehicle and house interfaces:

public interface IVehicle extends IPainted {
}

Is this the best way of representing adjectives?

like image 566
sdasdadas Avatar asked Nov 03 '22 06:11

sdasdadas


1 Answers

Yes. And to put both of your somewhat awkward designations of "noun" and "adjective" in the same bucket, use suffix "able" -- in this case public interface Paintable. So all the properties of a paintable class that have to do with paintability should be encapsulated within the Paintable interface which that class implements.

like image 68
amphibient Avatar answered Nov 14 '22 22:11

amphibient