嗯,在统一建模语言中有概念关联,所以我想用C#实现它。
/*在面向对象的编程中,关联定义了对象类之间的关系,允许一个对象实例使另一个对象实例代表它执行操作。这种关系是结构化的,因为它指定一种对象连接到另一种对象*/
你能告诉我如何编码对象之间的关联关系吗?
谢谢你
发布于 2010-07-31 09:51:11
StackOverFlowUser类与StackOverFlowUser生成StackOverFlowQuestion的StackOverFlowQuestion类相关联
class StackOverFlowUser
{
public StackOverFlowQuestion PostQuestion(string title, string msg)
{
//some logic
return new StackOverFlowQuestion(title, msg);
}
}
class StackOverFlowQuestion
{
public StackOverFlowQuestion(string title, string msg)
{
//more logic here
}
}发布于 2013-04-20 13:44:04
AirConditioner类与RemoteControl类相关联的方式是,RemoteControl类成为AirConditioner类的属性。所以我们可以说,AirConditioner类有一个名为RemoteControl的属性,但它本身也是一个完整的类。
class AirConditioner
{
//private members
private bool _airConditionerRunning;
private RemoteControl _myRemote;
//public method to access the remote
public RemoteControl returnMyRemote()
{
return _myRemote;
}
//Rest of properties and methods etc
}
class RemoteControl
{
//methods and peroperties of remoteControl Class
}https://stackoverflow.com/questions/3376418
复制相似问题