views:

91

answers:

2

Can some one tell me how can i map aggregation and composition in c#,considering the two classes STUDENT and LECTURER.

my question may be unclear.As an example,I used VS class designer to generate the Association relationship between classes.consider the 2 classes LECTURER and STUDENT_SOCIETY.Class Designer generates the following code. Blockquote

public class Lecturer
{
    private string Name;
    private string Specialization;

    public StudentSociety StudentSociety
    {
        get
        {

        }
        set
        {
        }
    }


}

public class StudentSociety
{
    private int Name;
    private string NoOfMembers;
}

So same way how can i model the aggregation and composition

+1  A: 

More information needed. Do you want to take your domain model and map it into a UML diagram? Usually it happens the other way (diagram first, then generate the model as code objects). There isn't anything built into C# or "vanilla" Visual Studio to do this; however, MS Visio (part of "Professional"-level Office installs) can go from diagram to code and back, and integrates with VS to do this. Last I worked with Visio, it wasn't "pure" UML; the diagram symbols borrowed from a combination of diagramming schemes. However, it'll get you a readable graphic representation of your model, and changes you make there can be re-emitted as code objects.

As far as actually determining the relationship between these, it's generally many-to-many, with the unifying context for a useable one-to-many relationship being a "class" or "section" of a "course" or "subject". A single course has many sections. Each section has one lecturer and many students. The same student can attend multiple sections, and the same teacher can teach multiple sections. That means that both the lecturer and student can have a list of sections they teach/attend (if you need a "two-way" domain model where you can navigate in any direction around the object graph).

KeithS
Visual Studio can generate Class Diagrams from code. They're similar to UML static diagrams.
Mark Cidade
Agree with @Keith. You don't mention the nature of the relationship(s) you're trying to capture - which is fundamentally important. Assuming it's along the lines of 'Lecturer teaches Student': (1) it's generally many:many (with some intermediate) and so (2) Aggregation/Composition aren't generally useful for this type of relationship.
sfinnie
Thanks for the replys plz see the EDIT
chamara
+1  A: 

Typically composition is permanent and representated by wholly containing one class within another whereas aggregation involves some sort of assignment or link.

So, assuming the lecturer is responsible for a number of students composition would be something like:

Public class Lecturer
{
    public class Student
    {
        string mName = "";
... etc.

Whereas aggregation could be:

Public class Lecturer
{
    ... Some code ...
}

Public class Lecturer
{
    Student mStudent;

    public void setStudent(Student theStudent)
    {
        mStudent = theStudent
    }

... etc.

Let me know if I get a good mark for your homework... ;)

FixerMark
typo - 1st line of aggregation example should be Public class Student (not Lecturer). Answer otherwise good. However - from a Domain perspective - I'd still question the notion of a lecturer "containing" or aggregating students (per comments above).
sfinnie
Quite right it should have been student - that'll teach me to cut and paste quickly.
FixerMark