Ads

We help in wordpress site design and developmet, contact us by completing the form.

Guide Object Orientated Programming (OOP concepts)

Taimoor Sattar Posted on

Object Orientated Programming

OOP languages focus is not on structure, but on data modeling. Object Orientated Programming (OOP) is a computer programming language model based on defining “objects” rather than “variables” and “logic”.
Popular OOP Languages: PHP, Java, Python, C++, .NET, RUBY

OOP Advantage

  • Code Reuse and Recycling
  • Encapsulation
  • Design Benefits
  • Software Maintenance

OOP Disadvantages

An object-orient approach is benefits to us when designing large-scale application. But some of the disadvantages are as follow

  • Can be more complicated to learn
  • Requires extra thinking

Key concepts of Object Orientated Programming(OOP)

  • Objects
  • Classes
  • Methods and Properties
  • Constructors/Destructors

What are a class and an object?

In object-oriented programming, the class is a blueprint or template which contain variables and function for creating an object. Therefore the object is an instance of the class. Objects have states and behaviors. An object has a state in which all of its variables have values that you either define by yourself or that are defined by default settings. The class is a category of objects.

What are abstract classes?

In a programming language, an abstract class is a generic class can not be instantiated and used directly It must be extended by another class. If a property or method is “abstract” then the class also MUST be “abstract”.

What is concrete Type class?

Concrete type class that is not abstract which can be instantiated is called a concrete type. Every instance of an abstract type is an instance of some concrete subtype.

Visibility

The class has function and variables whose accessibility outside the scope of the class is defined by us.

  • public – Accessible outside of class
  • protected – Accessible in class and any extended classes
  • private – Accessible ONLY in owner class

Can be attached to both properties and methods

Methods and Properties

The function takes some input, based on the input execute some instructions to achieve some result. It may take arguments and return the result. The procedure is a section of a program that performs a specific task.

function drawLine(x1, y1, x2, y2){
// draws a point A
// draw a point B
// Combine point A and B in a straight line
// return straight line
}

Member functions or method are functions attached to specific classes (or instances) in object-oriented programming. It is similar to functions, belongs to classes or objects and usually expresses the verbs of the objects/class.

Properties in programming language refer to the fields of objects/classes which is used to store some of the particular information.

How to instantiate and use a class

First, we have to define the class. Then out this class, we can call the class by its name and access its properties.

Getter and setter in OOP

A getter is a method that gets the value of a property. A setter is a method that sets the value of a property. Getters and setters are used in many object-oriented programming languages to ensure the principle of data encapsulation.
Getter and setter are useful to access the value and attribute of the class which is not accessible to the outside scope of the class. 

4 Pillar of Object-oriented programming OOP

  • Abstraction.
  • Encapsulation.
  • Polymorphism.
  • Inheritance.

Abstraction

Abstraction is a more generic term, it can also be achieved by subclassing. At an abstract level, there is no implementation details at all and focus on what’s important. It is the concept of describing something in simpler terms in order to focus on what is important. The same idea translates to OOP by using an inheritance hierarchy, where at the top abstraction; more concrete and focus ideas at the bottom.

Encapsulation

 Encapsulation refers to the state of objects. Objects encapsulate their state and hide it from the outside. In the outside scope, users can interact with the class through its methods and cannot access the classes attributes directly.

Inheritance

Classes can be extended to a child class. Child classes have access to all of its parent’s properties and methods unless the visibility of them is set to “private”.

Polymorphism

Polymorphism is the ability to process objects differently depending on their data type or class.

Other Concepts

This concept will be updated in the next update.

  • Autoloading class files
  • Object iteration
  • Autoloading Classes & Final keyword
  • Object Iteration
  • Magic Methods
Ads

We help in wordpress site design and developmet, contact us by completing the form.

From Our blogs

Leave a comment

Leave a Reply

Your email address will not be published. Required fields are marked *


Recent Comments
    No comments found.