I'm dealing with this problem. I'm creating math problems, each one has response. For example.
My big question is.
How would be the relation between the classes question and response. Also I was dealing if this should be an association, aggregation or composition.
Thanks.
EDIT: Great, it's a composition. Last thing, according to above sentences, how can I represent the design? These are some ideas what I have, but I guess I'm wrong.
public class Question
{
public Response _response;
//public List<Response>
//public Dictionary<string, Response>
public Question()
{
this._response = new Response();
}
}
public class Response
{
}
Association is a relationship where all object have their own life cycle and there is no owner. Let’s take an example of Teacher and Student. Multiple students can associate with a single teacher and a single student can associate with multiple teachers but there is no ownership between the objects and both have their own lifecycle. Both can be created and deleted independently.
Aggregation is a specialized form of Association where all objects have their own lifecycle but there is an ownership: a child object can not belong to another parent object. Let’s take an example of Department and teacher. A single teacher can not belong to multiple departments, but if we delete the department the teacher object will not be destroyed. We can think about it as a “has-a” relationship.
Composition is again a specialized form of Aggregation and we can call this as a “death” relationship. It is a strong type of Aggregation. Child objects does not have their life cycle and if the parent object is deleted all child objects will also be deleted. Let’s take again an example of relationship between House and rooms. A house can contain multiple rooms and there is no independent life for a room and a room can not belong to two different houses. If we delete the house its rooms will be automatically deleted. Let’s take another example relationship between Questions and options. Single questions can have multiple options and an option can not belong to multiple questions. If we delete a question its options will also be deleted.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With