Basic Concept from Object Oriented Analysis & Design

Modularity:

  • In modular programming, the code is divided into different ‘modules’ which are responsible for a particular functionality in the entire project.
  • This helps in development, debugging and maintenance of the code.
  • Typically, modules should be as independent of each other as possible, where independence means that changes to a module leads to minimal change in other modules.
  • Example:
    • Quora website might have modules for User Sign-up, Login, Posting Questions, Posting Answers, Up-voting, etc.

Composition & Aggregation:

  • Composition is a relationship where an owner/parent object is responsible for child’s lifetime.
  • Aggregation is a generalized form of Composition, where the child object is borrowed and parent need not worry about its lifetime.
  • Both of them are a kind of “HAS-A” relation.

Composition – Example 1:

  • House contains multiple rooms but a room belongs to only one house.
  • House owns all the rooms and if you destroy house, you automatically destroy all the rooms.

Aggregation – Example 2:

  • A room may contain multiple furniture but a furniture belongs to only one room.
  • Destroying a room will not destroy the furniture, you can easily move them out.

In other words,

  • Aggregation shows weak relationship​ and composition shows strong relationship.
    • Car has headlight is aggregation.
    • Car has an engine is composition.

Reusability/Inheritance:

  • Inheritance is a mechanism in which one object acquires all the properties and behaviors of a parent object.
  • It is an important part of Oops (Object Oriented programming system).
  • We can create new classes that are built upon existing classes. When we inherit from an existing class, we can reuse methods and fields of the parent class. Moreover, we can add new methods and fields in your current class also.
  • Inheritance represents the IS-A relationship which is also known as a parent-child relationship.
  • Syntax:
    • ChildClass extends ParentClass
    • extends is a keyword

Why use inheritance?

  • For Method Overriding (so runtime polymorphism can be achieved). – To be discussed
  • For Code Re-usability.

Terms in inheritance:

  • Class: A class is a group of objects which have common properties. It is a template or blueprint from which objects are created.
  • Sub Class/Child Class: Subclass is a class which inherits the other class. It is also called a derived class, extended class, or child class.
  • Super Class/Parent Class: Super-class is the class from where a subclass inherits the features. It is also called a base class or a parent class.
  • Re-usability: As the name specifies, re-usability is a mechanism which facilitates you to reuse the fields and methods of the existing class when you create a new class. You can use the same fields and methods already defined in the previous class.

Leave a comment

Design a site like this with WordPress.com
Get started