I’m developing an application in JAVA SE, with a database in SQL Server.
In this application, I will have three kinds of images:
- First Aid Symbols
- Danger Symbols
- EPIs Symbols
All the images have the following attributes:
imageID - intimageDescription - Stringimage - ImageIcon
Thus, the Fist Aid and the EPIs images need this attribute:
isUsedInRiskAssessment - boolean
My question: what is the best approach to implement this structure?
Inheritance: (image in the link)
http://img194.imageshack.us/img194/6871/inheritance.png
I know inheritance is many times called ‘evil’, but seems like a valid option in this case, except for having a subclass without any other attributes.
Separated Classes:
http://img580.imageshack.us/img580/511/separated.png
Or other?
In my business layer, I want to be able to return all the images (no matter wich type), to the GUI.
I also tought of having a class Image and another class called ImageType. But in this scenario, the Image, when the ImageType is Danger Symbols, would have a non used attribute – the isUsedInRiskAssessment.
This also affects the way I’m going to create the tables in the database.
Hope I’ve explained myself clear. Thanks.
Inheritance is not bad here. But sometimes it would be necessary to write code which would determine the actual type and to do casting, – you won’t like the code you’ll get.
That is why I’d suggest having sometimes unused
Booleanproperty. Actually, three values:true,falseandnullare what you need. But make sure you mention meaning of null value in your documentation.