小编Ent*_*ode的帖子

在对象中有一个对象列表是否正常?

我是OO设计的新手,我想知道对象是否包含其他对象列表的设计是否典型.一个例子如下:

// Person object containing a list of phone numbers
public class Person
{
    public Guid Id { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public List<Phone> Contacts { get; set; }

    public void AddPhoneNumber(Phone phone)
    {
        Contacts.Add(phoneNumber);
    }
}

// Phone object
public class Phone
{
    public Guid Id { get; set; }
    public string Name { get; set; }
    public string Number { get; set; }
}

// …
Run Code Online (Sandbox Code Playgroud)

c# oop

3
推荐指数
1
解决办法
100
查看次数

标签 统计

c# ×1

oop ×1