The 5 Relationships between Classes (Views: 100)
How do we find related classes with the right UML-Notation, means which relationship belongs to which code ?
Despite the fact that several advanced languages have come out of the OO Revolution, such as Java, C++, OP a lot of people are still designing their code with minimal design in mind.
UML was formed in attempt to unify the best (or most popular in this case) modelling methods in Object-Oriented Analysis and Design. Let's focus on the Class Diagram and learn the 5 Relationships with OP (ObjectPascal).
So good up design will actually shorten the development cycle, give you an idea of the resources you need, and how to end the project.
The 5 Relationships are:
Realisation new UML 1.4
The Class Diagram is the static architectural representation of your software and capable with a CASE-Tool to generate Code. It allows you to see the overall object structure of the system.
Let's start with the Inheritance (Generalization). All Relations are represented by Fig.1, (download cd_busobj.tif) but also by Code:
1) Inheritance is represented by a triangle and TBusinessObj is a subclass of TDataModule1, inheriting all of the members (Attributes and Operations) of the superclass.
TBusinessObj = class(TDataModule1)
function calcSalary(salary: double): Double;
procedure changeGrade(amount: integer);
constructor Create(aOwner: TComponent); override;
destructor destroy; override;
procedure changeSalary(amount: double);
function getFullName: string;
function getOldSalary: Double;
function open_QueryAll: Boolean;
function open_QuerySalary(qryID: integer): Boolean;
2) Association is represented by a line, means a relationship at runtime. In Fig.1 seen by from TDataToXML. Association is not a tight coupling between objects, you call it and free it at runtime with local instances:
procedure TForm1.btnToXMLClick(Sender: TObject);
with TDataToXML.create do
3) Aggregation is a whole-part relationship. A TDataModule1 has Queries from TQuery, so the white diamond is positioned near the container to represent the Queries are the parts of the DataModule. It means also a relationship at designtime, Query1 is a steady member of TDataModule1:
TDataModule1 = class(TDataModule)
procedure loadTree(myTree: TTreeView; fromFile: string);
procedure storeTree(myTree: TTreeView; toFile: string);
4) Composition is a stronger form of Aggregation. Composition is represented by a black diamond. For example in the VCL you can often find constructs like this: memo1.lines.add, so memo1 is TMemo and lines is TStrings. Means in our example if a class TForm1 has an instance and needs another instance too, there we have a composition:
with datEmployee.dataSource1 do
while not dataSet.EOF do
5) Dependency is a dotted arrow and not shown in our diagram. It is used to show that one UML Element depends upon another. Dependencies can be used to describe the relationship not only between classes, also packages, or components. In a Class Diagram you find it for ex. that one class depends on a type of another class and the class is part of a Library, like the VCL. In our case TDataModule1 depends upon TTreeView (TreeView uses ComCtrls). But it's TForm1 which really depends on TTreeView, cause the instance TTreeView1 is a member of the Form:
TForm1 = class(TForm)
procedure TDataModule1.storeTree(myTree: TTreeView; toFile: string);
with TFileStream.create(toFile, fmcreate) do
6) Interface support is like inheritance but there is a strict interface-specification and a class which supports the interface, marked in UML like a lollipop in the diagram or a dotted arrow from implement to interface:
IIncomeInt = interface(IUnknown)
function GetIncome(const aNetto: Currency): Currency; stdcall;
function GetRate: Real; stdcall;
TIncomeRealSuper = class(TInterfacedObject, IIncomeInt)
function Power(X: Real; Y: Integer): Real;
function GetRate: Real;
Interfaces works the same way in CLX or Kylix, as long as you don't use IDispatch from COM! So you don't need a MS-specific library to use interfaces.
Component Download: http://max.kleiner.com/download/businessobj.zip
<< Back to main page