Association (object-oriented programming) - Wikipedia
Object oriented programming generally support 4 types of relationships that are: inheritance, association, composition and aggregation. OOAD Object Model - Learn Object Oriented Analysis and Design in simple and easy steps starting from Some of its operations can be defined as follows − . Association depicts the relationship between objects of one or more classes. When a class definition uses another class as a parameter to a method, or declares an Associations are the most generic of the relationships between classes.
Furthermore, you also have to consider the higher level or business goals of the system you are modelling. We have objects like House and Room in our system under consideration, but cannot be strongly related via composition.
OOAD Object Model
For instance, if I am modelling a real estate system then I might have to know what room belongs to what house. But lets that I am modelling a surveying or census system where i want to know how many people are living in each room of the house in a certain area, then I just do not need to relate a room with a house via composition.
Another example could be of an orchard and certain kind of fruit. Lets say I can only consider an orchard when I have apple trees planted inside it. The bottom line is that the requirements of the overall system does matter a lot. Encapsulation is one of the pillars of Object Oriented Design. You need to bundle your data and the operations you will perform on your data.
When 2 objects are interacting, they have to interact each other via an interface.
OO Class Relationships | Atomic Object
And that's what encapsulation ensures about when we design our OO system. Here is how these concepts are applied to the code: Through encapsulation, the internal details of a class can be hidden from outside. 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.
OOAD - Object Model
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. Though the name and purpose of the methods in the classes are same, the internal implementation, i. When an object of class Circle invokes its findArea method, the operation finds the area of the circle without any conflict with the findArea method of the Square class.
Association (object-oriented programming)
Generalization and Specialization Generalization and specialization represent a hierarchy of relationships between classes, where subclasses inherit from super-classes. Generalization In the generalization process, the common characteristics of classes are combined to form a class in a higher level of hierarchy, i. Specialization Specialization is the reverse process of generalization. Here, the distinguishing features of groups of objects are used to form specialized classes from existing classes.
It can be said that the subclasses are the specialized versions of the super-class.
The following figure shows an example of generalization and specialization. Links and Association Link A link represents a connection through which an object collaborates with other objects.
Through a link, one object may invoke the methods or navigate through another object. A link depicts the relationship between two or more objects.Object Oriented programming ( OOP ) :- What is Aggregation , Association and Composition ?
Association Association is a group of links having common structure and common behavior.