- 浏览: 32517 次
- 性别:
- 来自: 杭州
-
最近访客 更多访客>>
最新评论
-
bbym010:
通俗易懂,不错
Build模式的理解 -
0000ps:
今天在MSDN上看到一段内容:
Value Object. S ...
Value Object vs. Data Transfer Object (VO vs. DTO)
这个问题不仅我们这些小喽罗会迷惑,很多大拿们也没有统一的认识,争论常有。
在UML2.0 规范中,有些以前归为一方的现在被归为另一方。
下面是从网上搜集的一些看法:
---------
1.
---------
Dependency Relationship
Draw a dependency relationship between two classes, or between a class and an interface, to show that the client class depends on the supplier class/interface to provide certain services, such as:
?The client class accesses a value (constant or variable) defined in the supplier class/interface.
?Operations of the client class invoke operations of the supplier class/interface.
?Operations of the client class have signatures whose return class or arguments are instances of the supplier class/interface.
A dependency relationship is a dotted line with an arrowhead at one end:The arrowhead points to the supplier class.
Association Relationship
An association provides a pathway for communication. The communication can be between use cases and actors, between two classes or between a class and an interface. Associations are the most general of all relationships and consequentially the most semantically weak. If two objects are usually considered independently, the relationship is an association
---------
2.
---------
Martin Fowler
If you have an association from Class A to Class B then that means every instance of class A has some kind of link to class B. Now exactly what people mean by "some kind of link" varies, it may be a conceptual link, a method of the form getA or a field inside class A. But the usual notion is that the link exists at all times (although if the lower bound is 0 it may be empty). This link can be used by any method of A and, if exposed, by other classes too.
With a parameter the connection between A and B only exists within the scope of the method that took the parameter. No other method can use the connection. As such that, for most people I come across, means that it is not an association.
The dependency means that if you change the interface of B then you may have to change A. An association usually implies a dependency, but not vice-versa, as the parameter example suggests.
---------
3.
---------
Robert C. Martin
However, association is not free of semantics. An association is a data relationship. i.e. the implementation must use some sort of data variable to implement it. Typically this is done with some kind of member variable or instance variable that refers to the associate. In C++ we might create a pointer variable, in Java a reference variable. Or we might use some kind of string that represents the associate in a dictionary somewhere.
In order for a message to be send between two objects, an association must exist between their two classes; and that association must be navigable in the direction that the message was sent.
---------
4.
---------
quote:
>What is the difference between Association and Dependency?
>My understanding so far was:
>If an object of class A has a reference to an object of class B in its
>attribute structure, it is association.
Robert C. Martin's answer:
Er, well, uh -- hmmm.
That's as good a definition as any I suppose. There are so many different colloquialisms and slangs for UML that I guess it hardly matters any more.
There was a time when an association was the channel between classes over which messages were sent. No message, no association. But that rule has been relaxed by so much conventional usage that I don't think it can hold any more.
Nowadays we seem to use association and aggregation interchangeably to represent a data field (except, of course, that everybody has their own private definition for what the white diamond means.) Dependency if very commonly used to represent an argument passed to a function. This was not the original intent of UML, but it's the way things have turned out.
There was a time when dependency meant that a class knew about another, but did not send messages. Data structures had dependencies on their members because they didn't send them messages, whereas classes had associations with their members because they did send them messages. But that nice separation has gotten so badly muddled that it has become useless.
Perhaps you can read from my tone that I'm pretty disillusioned with UML. Too bad. It could have been a standard. Now, I think its just going to be a confusing compendium of confounding conventions.
---------
5.
---------
//
From UML 2.0 Superstructure Final Adopted Specification:
"An association describes a set of tuples whose values refer to typed instances." (p. 97)
"A dependency is a relationship that signifies that a single or a set of model elements requires other model elements for their specification or implementation." (p. 124)
---------
6.
---------
依赖是比关联弱的关系,关联代表一种结构化的关系,体现在生成的代码中,以java为例:
若类A单向关联指向类B,则在类A中存在一个属性B b。
若类A依赖类B,则不会有这个属性,类B的实例可能存在于某个方法调用的参数中,或某个方法的局部变量中。
---------
7.
---------
关联有双向与单向之分,类A与类B双向关联可以是A与B相互可以作为对方的一个attribute,单向的话,就指其中一个类作为另一个类中的 attribute;依赖就只有单向的,不存在attribute的问题,例如类A依赖类B,表示在类A中有三种类B的使用方法:一是类B是全局的,二是类B在类A中实例化,三是类B作为参数被传递
---------
8.
---------
关联是一种结构关系,表现为一个对象能够获得另一个对象的实例引用并调用它的服务(即使用它);依赖是一种使用关系,表现为一个对象仅仅是调用了另一个对象的服务
欢迎大家拍砖...
在UML2.0 规范中,有些以前归为一方的现在被归为另一方。
下面是从网上搜集的一些看法:
---------
1.
---------
Dependency Relationship
Draw a dependency relationship between two classes, or between a class and an interface, to show that the client class depends on the supplier class/interface to provide certain services, such as:
?The client class accesses a value (constant or variable) defined in the supplier class/interface.
?Operations of the client class invoke operations of the supplier class/interface.
?Operations of the client class have signatures whose return class or arguments are instances of the supplier class/interface.
A dependency relationship is a dotted line with an arrowhead at one end:The arrowhead points to the supplier class.
Association Relationship
An association provides a pathway for communication. The communication can be between use cases and actors, between two classes or between a class and an interface. Associations are the most general of all relationships and consequentially the most semantically weak. If two objects are usually considered independently, the relationship is an association
---------
2.
---------
Martin Fowler
If you have an association from Class A to Class B then that means every instance of class A has some kind of link to class B. Now exactly what people mean by "some kind of link" varies, it may be a conceptual link, a method of the form getA or a field inside class A. But the usual notion is that the link exists at all times (although if the lower bound is 0 it may be empty). This link can be used by any method of A and, if exposed, by other classes too.
With a parameter the connection between A and B only exists within the scope of the method that took the parameter. No other method can use the connection. As such that, for most people I come across, means that it is not an association.
The dependency means that if you change the interface of B then you may have to change A. An association usually implies a dependency, but not vice-versa, as the parameter example suggests.
---------
3.
---------
Robert C. Martin
However, association is not free of semantics. An association is a data relationship. i.e. the implementation must use some sort of data variable to implement it. Typically this is done with some kind of member variable or instance variable that refers to the associate. In C++ we might create a pointer variable, in Java a reference variable. Or we might use some kind of string that represents the associate in a dictionary somewhere.
In order for a message to be send between two objects, an association must exist between their two classes; and that association must be navigable in the direction that the message was sent.
---------
4.
---------
quote:
>What is the difference between Association and Dependency?
>My understanding so far was:
>If an object of class A has a reference to an object of class B in its
>attribute structure, it is association.
Robert C. Martin's answer:
Er, well, uh -- hmmm.
That's as good a definition as any I suppose. There are so many different colloquialisms and slangs for UML that I guess it hardly matters any more.
There was a time when an association was the channel between classes over which messages were sent. No message, no association. But that rule has been relaxed by so much conventional usage that I don't think it can hold any more.
Nowadays we seem to use association and aggregation interchangeably to represent a data field (except, of course, that everybody has their own private definition for what the white diamond means.) Dependency if very commonly used to represent an argument passed to a function. This was not the original intent of UML, but it's the way things have turned out.
There was a time when dependency meant that a class knew about another, but did not send messages. Data structures had dependencies on their members because they didn't send them messages, whereas classes had associations with their members because they did send them messages. But that nice separation has gotten so badly muddled that it has become useless.
Perhaps you can read from my tone that I'm pretty disillusioned with UML. Too bad. It could have been a standard. Now, I think its just going to be a confusing compendium of confounding conventions.
---------
5.
---------
//
From UML 2.0 Superstructure Final Adopted Specification:
"An association describes a set of tuples whose values refer to typed instances." (p. 97)
"A dependency is a relationship that signifies that a single or a set of model elements requires other model elements for their specification or implementation." (p. 124)
---------
6.
---------
依赖是比关联弱的关系,关联代表一种结构化的关系,体现在生成的代码中,以java为例:
若类A单向关联指向类B,则在类A中存在一个属性B b。
若类A依赖类B,则不会有这个属性,类B的实例可能存在于某个方法调用的参数中,或某个方法的局部变量中。
---------
7.
---------
关联有双向与单向之分,类A与类B双向关联可以是A与B相互可以作为对方的一个attribute,单向的话,就指其中一个类作为另一个类中的 attribute;依赖就只有单向的,不存在attribute的问题,例如类A依赖类B,表示在类A中有三种类B的使用方法:一是类B是全局的,二是类B在类A中实例化,三是类B作为参数被传递
---------
8.
---------
关联是一种结构关系,表现为一个对象能够获得另一个对象的实例引用并调用它的服务(即使用它);依赖是一种使用关系,表现为一个对象仅仅是调用了另一个对象的服务
欢迎大家拍砖...
发表评论
-
Facade vs Proxy
2010-04-02 08:36 1231Question: i feel there is not m ... -
Aggregation v.s. Composition
2010-03-30 08:13 1392Aggregation Aggregation is a k ... -
UML中几种类间关系:继承、实现、依赖、关联、聚合、组合
2009-12-06 23:13 1266继承,泛化(Generalization) 指的是一个类( ... -
Build模式的理解
2009-11-26 23:23 2215Builder模式 是为了将构建复杂对象的组装过程和它的创建部 ... -
设计模式简图
2009-11-26 22:00 891... -
Proxy, Builder and Decoration 异同点
2009-11-09 13:52 0晚上写分打发打发法 -
面向对象设计原则
2009-11-07 09:43 730正如牛顿三大定律 ... -
Flyweight Pattern 享元模式
2009-09-29 16:07 908GOF:运用共享技术有效地支持大量细粒度的对象。 解释一 ... -
Using the Prototype pattern to clone objects
2009-09-27 15:48 924Prototype pattern is one of the ... -
Is a Java Immutable Class Always final?
2009-09-27 15:10 1544In response to my recent blog p ... -
Defensive copying
2009-09-27 14:46 1003A mutable object is simply an o ... -
Copy constructors
2009-09-27 14:29 821Copy constructors : provi ... -
Immutable objects
2009-09-27 14:13 879Immutable objects are simply ob ... -
Java Immutable Class
2009-09-27 14:09 2012Java Immutable Class[ From ] ... -
Value Object vs. Data Transfer Object (VO vs. DTO)
2009-09-18 10:31 1662The pattern which is known toda ...
相关推荐
UML 中关联、泛化、依赖、实现的几种...UML 中的关联、泛化、依赖、实现等关系是我们设计软件系统时需要正确理解和掌握的关系,这些关系可以帮助我们更好地设计软件系统,提高软件系统的可维护性、可扩展性和可重用性。
UML 中依赖泛化关联实现聚合组合的 C# 实现 ...UML 中依赖泛化关联实现聚合组合的 C# 实现是我们软件设计中非常重要的一部分,我们需要充分了解 UML 中类与类之间的关系,并使用合适的编程语言和工具来实现它们。
在本主题中,我们将深入探讨四个核心概念:类、接口、依赖和关联。** **1. UML 类(Class)** 类是UML中最基本的构造块,代表了现实世界中的对象或概念。类通常包含属性(Attributes)和操作(Operations)。属性...
本文将深入探讨UML中的五个关键关系:继承、实现、依赖、关联和聚合,以及它们在软件设计中的作用。 1. **继承(Inheritance)**: 继承是面向对象编程的核心概念之一,它允许一个类(子类或派生类)从另一个类...
本文将详细探讨UML中的一些关键概念,包括依赖、泛化、关联、聚合、组合以及实现,并结合C#语言给出具体实现示例。 1. 泛化(Generalization): 泛化关系在UML中代表了继承,它表示一个类(子类)继承自另一个类...
今天,我们将探讨UML类关系中的四种基本关系:依赖、关联、聚合和组合。 依赖(Dependency) 依赖关系是指一个类使用另一个类的对象或服务的关系。依赖关系是一种弱关系,表示一个类需要另一个类的支持,但不拥有...
本文将深入探讨UML类关系中的四种关键概念:依赖、关联、聚合和组合,以及它们在软件设计中的应用。 1. 依赖(Dependency) 依赖是UML中最弱的一种关系,表示一个类(或对象)的实现或行为需要另一个类(或对象)的...
4. **依赖和关联的区别:** - 关联关系可以是双向的,而依赖关系一定是单向的。 #### 四、聚合/组合 **概念:** 聚合和组合都表示类之间的整体与部分关系。它们之间的区别主要在于整体与部分之间的关系强度。 1....
本文将详细介绍UML类图中的六种基本关系:依赖、类属、关联、实现、聚合和组合。 #### 二、依赖(Dependency) **定义**: - 当元素A的变化会影响元素B,但元素B的变化不会反过来影响元素A时,我们说B依赖于A。 - ...
本文将深入探讨UML类图中的几种关键关系:关联、组合、聚合、依赖,这些关系构成了类之间互动的基础框架。 #### 关联关系(Association) 关联关系是类与类之间的最基本连接,它描述了类之间的静态结构关系。关联...
UML中的六大关系——依赖、泛化(类属)、关联、实现、聚合和组合,构成了理解软件系统结构的基础。 ### 依赖(Dependency) 依赖关系是最弱的一种关系,表示一个类(或组件、用例等)使用了另一个类的接口,这种...
它展示了系统中类的属性、操作(方法)和类之间的关系,如关联(Association)、依赖(Dependency)、聚合(Aggregation)和组合(Composition)。类图在软件工程中非常重要,因为它直接反映了系统设计的核心要素。 ...
类图是UML中的静态结构模型,用于描述系统中的类、对象、接口、继承、实现、关联、聚合、组合、依赖等关系。 类图符号可以分为以下几类: 1. 类(Class):使用三层矩形框表示,第一层显示类的名称,如果是抽象类...
UML(Unified Modeling Language)是一种标准化的建模语言,用于软件开发过程中表示系统的结构和行为。类图是UML中最基础的图表之一,它用于描绘类与类之间的静态结构关系。下面我们将详细解释UML类图中各符号的含义...
类间关系描述了类与类之间的各种联系,包括依赖(Dependency)、关联(Association)、聚合(Aggregation)、合成(Composition)和泛化(Generalization)等。依赖关系指的是一个类使用另一个类,如果依赖关系发生...
关系(Relationships)如关联(Association)、依赖(Dependency)、泛化(Generalization)和实现(Realization)连接了模型中的不同元素,揭示了它们之间的相互作用。 在实际应用中,UML的建模过程通常分为以下...
本文将深入解析UML中的四种基本关系:泛化(Generalization)、关联(Association)、依赖(Dependency)和聚合(Aggregation),并提供具体的实例和代码示例。 #### 泛化(Generalization) 泛化关系体现了类之间的...
- **类(Class)**:代表现实世界中的对象或概念,包含属性、操作和关联。 - **对象(Object)**:类的实例,具有特定的属性值。 - **接口(Interface)**:定义了对象可以提供的服务,不包含实现细节。 - **关联...
在UML中,关系分为七种:继承关系、实现关系、依赖关系、关联关系、有方向的关联、聚合关系和组合关系。 1. 继承关系(Generalization) 继承关系是一种类与类、接口与接口之间的关系,指的是一个类(子类)继承...
在 UML 类图中,一个类通常由三部分组成:类名、属性(字段)和方法(操作)。类名位于矩形框的第一层,属性和方法分别位于第二层和第三层。例如,在“动物”矩形框中,类名为“Animal”,第二层显示其属性和方法。 ...