C# 中的 UML 映射

发布于 2024-09-19 17:12:59 字数 487 浏览 4 评论 0原文

有人可以告诉我如何在 C# 中映射聚合和组合,考虑到学生和讲师这两个类。

我的问题可能不清楚。作为一个例子,我使用VS类设计器生成类之间的关联关系。考虑2个类LECTURER和STUDENT_SOCIETY。类设计器生成以下代码。 Blockquote

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

    public StudentSociety StudentSociety
    {
        get
        {

        }
        set
        {
        }
    }


}

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

那么同样的方式我如何建模聚合和组合

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

◇流星雨 2024-09-26 17:12:59

通常,组合是永久性的,并通过将一个类完全包含在另一个类中来表示,而聚合则涉及某种分配或链接。

因此,假设讲师负责许多学生的作文,则类似于:

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

而聚合可能是:

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

Public class Lecturer
{
    Student mStudent;

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

... etc.

如果我的作业取得了好成绩,请告诉我...;)

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... ;)

迷迭香的记忆 2024-09-26 17:12:59

需要更多信息。您想要将您的领域模型映射到 UML 图中吗?通常它会以另一种方式发生(首先绘制图表,然后将模型生成为代码对象)。 C# 或“vanilla”Visual Studio 中没有内置任何东西来执行此操作;然而,MS Visio(“专业”级 Office 安装的一部分)可以从图表到代码并返回,并与 VS 集成来执行此操作。上次我使用 Visio 时,它并不是“纯粹的”UML;而是“纯粹的”UML。从图表方案组合中借用的图表符号。但是,它将为您提供模型的可读图形表示,并且您所做的更改可以作为代码对象重新发出。

就实际确定它们之间的关系而言,通常是多对多,可用的一对多关系的统一上下文是“课程”或“主题”的“类”或“部分”。一门课程有很多部分。每个部分有一名讲师和多名学生。同一学生可以参加多个部分,同一位老师可以教授多个部分。这意味着讲师和学生都可以拥有他们教授/参加的部分的列表(如果您需要一个“双向”域模型,您可以在对象图周围的任何方向上导航)。

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文