2010-07-31 5 views
0

UML의 개념 연관이므로 C#을 사용하여 구현하고 싶습니다.객체 지향 프로그래밍 : 연결

/* 개체 지향 프로그래밍에서 연결은 한 개체 인스턴스가 다른 개체 인스턴스를 대신하여 작업을 수행하게하는 개체 클래스 간의 관계를 정의합니다. 이 관계는 하나의 종류의 객체가 다른 객체의 객체와 연결된다는 것을 명시하기 때문에 구조적입니다. */

객체 간의 연관 관계를 어떻게 코딩 할 수 있습니까?

감사합니다

+0

www.eliminatecodefear.com의 "마스터 객체 지향 설계"과정을 가지고 - 제 생각에는, 그것이 두드러지게 OOP HW 할당과 실제 객체 지향 설계 및 개발 학습을위한 온라인 최고의 자원 중 하나입니다 . (HW는 그렇지 않으면 매우 중요합니다. 귀찮게해서는 안됩니다.) –

답변

1

StackOverFlowUser 클래스가 StackOverFlowQuestion 클래스와 연관되어

StackOverFlowUser는 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 
    } 

} 
+0

Nice. 당신은 저를 웃게 만들기위한 표를 얻습니다 ...하지만 어딘가에 닫는 중괄호가 없습니다. – Jack

2

에어컨 클래스가 RemoteControl이 클래스는 에어컨 클래스의 소유가있는 방식으로 RemoteControl이 클래스와 연관되어 있습니다 . 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 
}