Association classes and Inheritance
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Gavin_Selvaratnam
Posted On:   Friday, January 11, 2002 09:06 AM

Hi, I have two questions. (1). Association Class I have two classes Artifact and Issue. An Issue can have 0..* relevant Artifact and an Artifact can be associated with 0..* Issues. Can you please sudgest a association class that is meaningfull for this relatioship. (2). Inheritance. I have two classes Response and Issue. In the system an Issue will have 0..* Responses. The two classes have many attributes and methods wich are exactly the same. I'm trying to create an abstract class for them. Can you plase tell me whther what I'm doing is correct and can you sudgest a meaningfull class name. Thankyou verry much    More>>


Hi,
I have two questions.


(1). Association Class

I have two classes Artifact and Issue. An Issue can have 0..* relevant Artifact and an Artifact can be associated with 0..* Issues. Can you please sudgest a association class that is meaningfull for this relatioship.


(2). Inheritance.

I have two classes Response and Issue. In the system an Issue will have 0..* Responses. The two classes have many attributes and methods wich are exactly the same. I'm trying to create an abstract class for them. Can you plase tell me whther what I'm doing is correct and can you sudgest a meaningfull class name.




Thankyou verry much

   <<Less

Re: Association classes and Inheritance

Posted By:   Bozidar_Dangubic  
Posted On:   Saturday, January 12, 2002 03:56 AM


  1. there is no such thing as a meaningful association class for this relationship. the only meaningful association class is that which is meaningful in your application. in reality, this should not be modeled with association classes because the association between Issue and Artifact does not have properties that should not be modeled in either of the classes. you use association classes when the association itself has properties. for instance, an association between a Company and a Person is Job which does have properties such as dateHired, description of the Job and salary. these properties really do not belong in neither Person nor Company but in the relationship between a Person and a Company. hence the need for association class. if I was you, I would model the association between Artifact and Issue as simple association with 0..* at both ends unless you know that there are properties that should be associated with that association. if you know that they are, the name and structure of the association class should be very easy to come up with.
  2. just because two classes have similar attributes and methods does not necessarily mean that they should be in the same inheritance hierarchy. there are many entities that can possess similar properties. for instance, you can have a Person and a Fridge object both of which have a method called getTemperature(). of course, Person and Fridge should not be in the same inheritance hierarchy. never use inheritance simply because two object share some common properties. think of your application and ensure that if you do define inheritance hierarchy that in all instance of your problem domain substitution of subclasses with the superclass is a valid. for instance, in my previous example, in the application that has a Person object and Fridge object, and given that Fridge is a subclass of Person, can I always substitute a Person for a Fridge and have a valid logic. that is what the inheritance is all about. substituitability. if application has a method recycle() that takes Fridge as a parameter, is it valid to substitute a Person, a superclass of the Fridge object, in the method call. obviously we do not recycle humans and therefore for the current application there should be no inheritance between Person and Fridge. also beware of the meaning of the methods that are getting inherited. if for instance, in addition to getTemperature() or Person and Fridge object had a method named consumeFood(Food food). even though method signature is the same, the method has a completely different meaning for the Person class than it does for the Fridge class. all in all, similar methods and attributes in two object does not justify placing them in the same inheritance hierarchy.
About | Sitemap | Contact