# Object Oriented Programming

oopobjectorientedprogrammingparadigm

# UML - Unified Modelling Language

Tools

  • GitUML
    • Revolutionize code documentation and code visualization
  • Pyreverse - Pylint

# 💹 UML Diagram

UML - Unified Modelling Language

structure of a software system

# Entities / Classes

# Relationships

Deligating Responsibility

  1. Inheritance --|>
  2. Assocaition
  3. Aggregation - has a
    1. can exist without source object and independently
  4. Composition - is a part of
    1. has the scope and lifetime of called object, cannot exist without it

Check documentation

# Composition
class Employee:
    def __init__(self, name, pay, bonus):
        self.name = name
        self.emp_salary = Salary(pay, bonus)
# Aggregation
class Employee:
    def __init__(self, name, pay, bonus, Salary):
        self.name = name

# Multiplicity

  • How is it all done in Python?

# OOP - Object Oriented Programming Concepts

# 🚰 Polymorphism wiki

Static (compilet time) or Dynamic (run time) implementation

provision of a single interface to entities of different types

# 1. Ad-hoc Poylmorphism

common interface for an arbitrary set of individually specified types.

Operator Overloading wiki
  • aka adhoc Polymorphism, syntactic sugar
  • Different implementations based on arguments

Eg,

  1. In javascript and python, + operator acts either as arithmetic addition or string concatination based on the type of arguments
print(1 + 2)
print("Avi" + "Mehenwal")
print("Avi" * 4)     # repeat 4 times
Whats the difference between operator overloading and overriding?

The main difference between overloading and overriding is that in overloading we can use same function name with different parameters for multiple times for different tasks with on a class. and overriding means we can use same name function name with same parameters of the base class in the derived class. this is also called as re useability of code in the programme.

Polymorphic functions can be supplied with arguments of different types

Functional Overloading

Functions of same name with different implementations

For example, doTask() and doTask(object O) are overloaded functions.

Operator Overloading

Different operators have different implementations based on their argument

For example, use of + and * operator in python language

Useful Links for this topic

# 2. Parametric Polymorphism

Function usage doesnt not depend on argument type, implementation takes care of it Skip providing types with arguments

A function or a data type can be written generically so that it can handle values identically without depending on their type.[1] Such functions and data types are called generic functions and generic datatypes respectively and form the basis of generic programming.

For example, a function append that joins two lists can be constructed so that it does not care about the type of elements: it can append lists of integers, lists of real numbers, lists of strings, and so on.

# 3. Subtyping / Inclusion Polymorphism

when a name denotes instances of many different classes related by some common superclass

Why need it? whats the advantage?

to restrict the range of types that can be used in a particular case of polymorphism

Uses Inheritance principles of base class and super class

Subtyping and Supertyping

is said to be a supertype of

Type and subtype of

  • or
  • Buy me a coffeeBuy me a coffee