What is encapsulation in OOPs
associationAn association describes a relationship between two types, in the most common case a connection between two objects of the classes
An association forms a kind of bridge between two types: if you start with the instance of the one involved type, you can navigate to the instance of the second type via an object relationship.
An exact definition is not given in UML2, rather it is pointed out that an aggregation varies depending on the application and modeler. A concrete benefit can be derived, for example, by giving special emphasis to one end of an association.Basically, the distinction between association and aggregation is difficult. A weak indicator for the sensible use of an aggregation seems to be the existence of transitivities between the modeled classes. That is, if there is a part / whole relationship between A and B and also between B and C, then A must also be part of C.
compositionThe composition describes the relationship between a whole and its parts. A part can only ever be assigned to exactly one whole. Parts that are connected to a whole via a composition may appear in at most one (0..1) whole.
Data encapsulationIn programming, data encapsulation is the term used to describe the hiding of data or information from outside access. Direct access to the internal data structure is prevented and instead takes place via defined interfaces.
- public (+)
- accessible for all versions (including those of other classes),
- private (-)
- Only accessible for versions of their own class,
- protected (#)
- Only accessible for versions of their own class and specializations of the same,
Benefits of Encapsulation
- Since the implementation of a class is not known to other classes, the implementation can be changed without affecting the interaction with other classes.
- Increased clarity, since only the public interface of a class has to be considered.
- When accessing via an access function, it does not matter from the outside whether this function exists 1: 1 inside the class, is the result of a calculation, or possibly comes from other sources (e.g. a file or database).
- Significantly improved testability, stability and changeability of the software or its parts (modules).
Disadvantages of the encapsulation
- Depending on the application, speed losses due to the call of the method (direct access to the data elements would be faster).
- Additional programming effort for creating the access methods.
importancePolymorphism ' (polymorphism = diversity) is next to Encapsulation and Inheritance the third pillar of the OOP. All object-oriented languages support this concept: apparently similar objects can differ in behavior.
The Polymorphism of object-oriented programming is a property that is always related to Inheritance occurs.
- Means that a single variable can be used for different objects of related classes (at different times) in a program.
- If the variable with the dot notation variable.methode () is used to call a method, it depends on the object which the variable is currently referring to, which method is actually being executed.
The whole thing is with virtual Methods of Base classes realized. It is only through these methods that this becomes possible "Child classes" using the same methods as that virtual methods of the base classesto overwrite them when the program is running.
For example, in a Base class TFigur a method TFigur.MaßeBeechnen exist. This method can be used by a Child class Treieck must be overwritten, as the dimensions of a triangle are now to be calculated.
InheritanceIn object orientation, inheritance is a procedure for building new constructs (classes or prototypes) hierarchically using existing ones.
The definition of a new class can, if necessary, build on the definition of an already existing class so that the new class takes over the characteristics of the existing ones and adds new components. The adoption of the characteristics of the existing class is called inheritance.
In inheritance is between Interface inheritance and Implementation inheritance to distinguish. With interface inheritance, a derived class inherits the signatures of methods, but has to implement the methods itself. With implementation inheritance, the derived class also inherits the implementation from one or more base classes or the implementation of the prototype.
If a new characteristic covers a characteristic that was inherited, then we speak of overwriting.
Inheritance can be used if there are classes that conceptually build on one another. If necessary, class definitions can be divided from the outset in such a way that identical features are combined in the definition of an inheriting class.
Example: interface inheritance
A vehicle has certain attributes, such as maximum speed, maximum payload or color. The motor vehicle class inherits all of these attributes, but can also have additional attributes, e.g. power or torque. Furthermore, a motor vehicle can also have additional methods, such as acceleration, which the vehicle base class does not know.
The passenger car class can then in turn be derived from motor vehicle and have additional attributes such as the number of seats. By deriving from motor vehicle, the passenger vehicle automatically inherits all attributes from vehicle.
A simple is-a rule can be used to determine whether a class is inherited from another class. As soon as the statement (object of the derived class) is a (object of the base class) applies, both classes are in an inheritance relationship.
|A passenger car is a motor vehicle, but a passenger car is a vehicle|
A vehicle is not a passenger car.
A passenger car is not a seat
A passenger car has a seat.
Example: multiple inheritance
|Multiple inheritance - in contrast to multilevel inheritance - is when a class inherits directly from several classes.|
An application example for this is the modeling of an amphibious vehicle that inherits the attributes of both land vehicles and water vehicles. This means that the amphibious vehicle has both a number of wheels and a depth.
- Are actors overrated in Kollywood
- What happens after the angel hits
- Where did vampire-repellent vampires come from?
- What is vector graphics printing
- What is HR automation
- How are plastic water bottles made
- What is shift in time series
- How do I post ads on Twitter
- Can I transfer Bitcoin Coinbase to Zebpay?
- What are the hostel fees for JGEC
- Is postmodernism the opposite of Marxism
- What is the application of SQL
- How can you gain photographic memory
- Why is Chipotle hot
- Things to do before you are 18
- What do you hate about military films
- What is the largest size training bra
- What is a hedgehog
- What is radial and lateral speed
- Where's the cleat on a boat
- Do you know SOUL MORTAL
- What is classical algebra
- Is the coolant of the radiator flammable?
- What should I ask a graduate school
- Is Bither a secure bitcoin wallet
- How to Microdose Psilocybin
- What is the benefit of nanotechnology 1
- Everyone else is a philosophical zombie
- Why did Netflix Family Guy take off
- Is the Kegel exercise scientific?
- Is Filariasis Lymphatic Filariasis 100 curable
- What causes depression after masturbation
- What does the German word sry mean?