Dependency, Generalization, Association, Aggregation, Composition in Object Oriented Programming
In object-oriented programming, association defines a relationship between classes of objects In generic terms, the causation is usually called "sending a message", "invoking a method" or "calling a member function" to the controlled object. This article will explain some of the Object Oriented Programming Association: also called a "has-a" relationship that says one class is. OOAD Quick Guide - Learn Object Oriented Analysis and Design in simple and easy Functional Modelling, UML Approach of Analysis, Object Oriented Design , Association depicts the relationship between objects of one or more classes.
Objects can be modelled according to the needs of the application.
OOAD Quick Guide
An object may have a physical existence, like a customer, a car, etc. Class A class represents a collection of objects having same characteristic properties that exhibit common behavior. It gives the blueprint or description of the objects that can be created from it.
Creation of an object as a member of a class is called instantiation. Thus, object is an instance of a class. Generally, different objects of a class have some difference in the values of the attributes. Attributes are often referred as class data. A set of operations that portray the behavior of the objects of the class. Operations are also referred as functions or methods. Example Let us consider a simple class, Circle, that represents the geometrical figure circle in a two—dimensional space.
Encapsulation and Data Hiding Encapsulation Encapsulation is the process of binding both attributes and methods together within a class. Through encapsulation, the internal details of a class can be hidden from outside.
OOAD - Quick Guide
It permits the elements of the class to be accessed from outside only through the interface provided by the class. Data Hiding Typically, a class is designed such that its data attributes can be accessed only by its class methods and insulated from direct outside access. It should instead be accessed through the methods setValues and getValues. Message Passing Any application requires a number of objects interacting in a harmonious manner.
Objects in a system may communicate with each other using message passing. Suppose a system has two objects: The object obj1 sends a message to object obj2, if obj1 wants obj2 to execute one of its methods. Message passing enables all interactions between objects. Message passing essentially involves invoking class methods. Objects in different processes can be involved in message passing.
Inheritance Inheritance is the mechanism that permits new classes to be created out of existing classes by extending and refining its capabilities. The subclass can inherit or derive the attributes and methods of the super-class es provided that the super-class allows so. Besides, the subclass may add its own attributes and methods and may modify any of the super-class methods. Humans, cats, dogs, and cows all have the distinct characteristics of mammals.
In addition, each has its own particular characteristics. The following figure depicts the examples of different types of inheritance.
Polymorphism Polymorphism is originally a Greek word that means the ability to take multiple forms. In object-oriented paradigm, polymorphism implies using operations in different ways, depending upon the instance they are operating upon.
Polymorphism allows objects with different internal structures to have a common external interface. Polymorphism is particularly effective while implementing inheritance. Example Let us consider two classes, Circle and Square, each with a method findArea. It shows that an organization may contain 0 to 20 teams and 0 to 1, workers. Furthermore, each team has 2 to 5 workers and each worker may be a member of 0 to 2 teams.
In addition, a team may contain 0 to 3 subteams. To determine if you should use an aggregation or composition, ask yourself a few questions. First, if the classes are related to one another, use an association. Next, if one class is part of the other class, which is the whole, use aggregation; otherwise, use an association.
For example, Figure shows that workers are part of a team and organization, teams are part of an organization, and subteams are part of teams. Finally, if the part must belong to one whole only, and the whole is responsible for creating and destroying its parts, use composition; otherwise, simply use aggregation.
For example, Figure shows that a team and worker must belong to one organization only, and the organization is responsible for determining or creating and destroying its teams and workers.
It also shows that a subteam must belong to one team only, and the team is responsible for determining or creating and destroying its subteams.
Lecture Notes on Object-Oriented Programming
If this is unclear, keep things simple and use associations without aggregation or composition. Composition also may be shown by graphically nesting classes, in which a nested class's multiplicity is shown in its upper-right corner and its rolename is indicated in front of its class name. Separate the rolename from the class name using a colon.
Figure uses the graphical nesting of teams and workers in organizations to communicate the same information as shown in Figure Alternate form of composition for associations Figure uses the graphical nesting of subteams within teams to communicate the same information as Figure and Figure The result is a nested class inside a nested class.
Doubly nested composition for associations 3. For example, Figure shows that multiplicity between work products and units of work is zero or more for both associations; that is, there may be many work products associated with a single unit of work and there may be many units of work associated with a single work product. Rather than simply say that there are "many" objects involved in the relationship, you can communicate a more finite number.
You can reduce the multiplicity between work products and units of work by asking yourself what you need to know about a unit of work so that you can define a more specific multiplicity one that isn't unbounded on the high-end. Likewise, you can ask yourself the same question about the association between work product and units of work. If you have a work product and the name of a unit of work, you can determine whether a relationship exists between the two; likewise, if you have a unit of work and the name of a work product, you can determine whether a relationship exists between those two.
The trick is to document precisely what information is needed so you can identify the objects on the other end of the relationship.
This is where the qualifier comes into play. Essentially, a qualifier is a piece of information used as an index to find the objects on the other end of an association.
- 3.2 Associations and Links
- Association (object-oriented programming)
- OOAD - Object Model
A qualifier is shown as a small rectangle attached to a class where an object of the class, together with a value for the qualifier, reduces the multiplicity on the other end of the association. Qualifiers have the same notation as attributes, have no initial values, and must be attributes of the association or the class on the other end of the association.
The relationships between work products and units of work and their qualifiers are shown in Figure The qualifiers indicate that a work product with the name of a unit of work may identify a unit of work, and that a unit of work with the name of a work product may identify a work product. Notice that I've reduced the multiplicity of The qualifier enables me to do this.
As a UML rule, qualifiers are used only with binary associations. Qualifiers for associations 3. For example, the project management system involves various specific relationships, including specific manage, lead, execute, input, output, and other relationships between specific projects, managers, teams, work products, requirements, systems, and so forth.
A link is an instance of an association, and the UML supports different types of links that correspond to the different types of associations.
The general rules for representing links in a UML diagram are as follows: Label links with their association names, and underline the names to show that they are specific instances of their respective associations. Ensure that link ends are consistent with their corresponding association ends. Translate association multiplicity into one or more specific links between specific objects.
The next few sections show how to apply these rules to the various link types. For example, a specific worker is related to specific units of work and work products in the project management system.
A link may have its association name shown near the path fully underlinedbut links do not have instance names. Figure shows various objects associated with the classes shown in Figure and the association classes shown in Figure Additionally, Figure includes several link objects. Figure describes an anonymous worker that performs a projecta unit of workthat consumes a Problem Statement work product and produces a system work product.
ResponsibleFor and Performed are two links in Figure Binary links The only difference between a binary link and a binary association is that the binary link is specific, and thus has its association name underlined.
For example, the utilization of a specific worker involves the worker, the worker's specific units of work, and the worker's specific work products in the project management system. A link may have its association name shown near the path, and because a link is specific, its association name should be fully underlined. However, links do not have instance names. As a UML rule, aggregation, composition, and qualifiers may not be used with n-ary links.
Additionally, Figure includes a link object named Utilization.
Figure describes the utilization of an anonymous team, its work, and work products. Structural features include attribute values and perhaps other links. Behavioral features include operations and methods, which are shared by all the links of an association class. Whenever an association has a related association class, each of its links has a corresponding link object. This link object defines attribute values for the link's structural features.
In addition, the behavioral features defined by the link's association class apply to the link objects.
OOAD Object Model
In a UML object diagram, a link object is shown as an object rectangle attached by a dashed-line path to its link path in a binary link, or attached to its link diamond in an n-ary link.
As with all UML elements representing specific objects or links, link object names should be fully underlined. Figure shows link objects for the binary associations in Figureand Figure shows a link object for the n-ary association in Figure A link end may show its association end's rolename, navigation arrow, aggregation or composition symbol, and values for its association end's qualifiers.
For example, Figure shows that a Worker is responsible for a WorkProduct. The specific association used is ResponsibleFor; this same association name is used again in Figure to describe the specific links between a specific Worker and the two specific work products: For example, the arrows on the two ResponsibleFor links in Figure both point to instances of WorkProduct.
This is consistent with Figurewhich shows the arrow for the ResponsibleFor association pointing to the WorkProduct class.
This is because an association describes the multiplicity between two or more classes of objects. A link however, is between specific objects.