Docsity

Principles of OOP: Abstraction, Encapsulation, Inheritance, Polymorphism, Assignments of Object Oriented Programming

Partial preview of the text

Download Principles of OOP: Abstraction, Encapsulation, Inheritance, Polymorphism and more Assignments Object Oriented Programming in PDF only on Docsity!

parsa riaz

Parsa riaz

Fa18-bse-

The main principles of object-oriented programming are:

  1. Abstraction
  2. Encapsulation
  3. Inheritance
  4. Polymorphism
  5. Association
  6. Aggregation
  7. Composition

Abstraction

Abstraction aims to hide complexity from the users and show them only the relevant information  Hides the underlying complexity of data  Helps avoid repetitive code  Presents only the signature of internal functionality  Gives flexibility to programmers to change the implementation of the abstract behaviour  Partial abstraction (0-100%) can be achieved with abstract classes  Total abstraction (100%) can be achieved with interfaces

Encapsulation

Encapsulation allows us to protect the data stored in a class from system- wide access.  Restricts direct access to data members (fields) of a class.  Fields are set to private  Each field has a getter and setter method  Getter methods return the field  Setter methods let us change the value of the field  Restricts direct access to data members (fields) of a class.  Fields are set to private  Each field has a getter and setter method  Getter methods return the field  Setter methods let us change the value of the field

Aggregation

Aggregation is a narrower kind of association. It occurs when there’s a one-way (HAS-A) relationship between the two classes you associate through their objects  One-directional association.  Represents a HAS-A relationship between two classes.  Only one class is dependent on the other.

Composition

Composition is a stricter form of aggregation. It occurs when the two classes you associate are mutually dependent on each other and can’t exist without each other  A restricted form of aggregation  Represents a PART-OF relationship between two classes  Both classes are dependent on each other  If one class ceases to exist, the other can’t survive alone Vedio link: https://youtu.be/n5aTr9hsO6g