IPH Technologies
Software & App Development company
Select Page

Introduction:

The full name of OOPs is Objected Oriented programming Language. OOPs is very important concept, on which almost all modern programming language stands.
SWIFT, APPLE’s trending language is no different from this. OOPs concepts are the backbone of SWIFT.
Let’s come to the topic which we will cover up in OOPs.
. Classes
. Objects
. Methods
. Access Control
. Encapsulation
. Abstraction
. Inheritance
. Polymorphism

Let’s see each topic one by one:-

Classes:
(1)
classes are the blueprints of the objects.
(2) classes are combination of data members and functions.
(3) classes are not a real-world entity that’s why it does not occupy memory.

 

Syntax:
oops

iOS Example:

UIView, the iOS’s main UI class, can be considered a class.

 

Objects:
(1)
Object is instance of  class.
(2) Object is a real-world entity that’s why it occupy memory.
(3) E.g, Dog, Cat, Pen, Pencil, etc, everything is an object. From our Person example, men and women are examples of objects which belong to the same class i.e Person.

Syntax:

iOS Example:

When we create an outlet of UITableView, then we create an object of UITableView class.

Methods:
Methods or Functions are the behaviour of the objects of a class. Let us say a person can walk, sing, play, etc irrespective of any object(Man/Woman). These all can be said to be methods/functions of the class.

Coding Syntax:
Methods syntax

 

iOS Example:

UIView class has many methods. Eg. “setNeedsLayout()”, which we call if we want to forcefully reset our UI layout.

Access Control:
Swift provides quite many handy access control levels which are really helpful while writing our code. Some of the access levels provided SWIFT:

 

Encapsulation:
Encapsulation is a concept by which we hide data and methods from outside intervention and usage.

Coding Example:
oops1

What we did here:

In the above example, we encapsulated the variable “result” by using the access specifier “private”. We hide the data of variable “result” from any outside intervention and usage.

Abstraction:
Abstraction is hiding the details or internal implementation, it’s highlight a set of service that we are offering.
E.g:-
ATM Machine, Electric circuit.

Inheritance:
Inheritance is defined as a process by which you inherit the properties of your parent. Technically, Inheritance is a process by which a child class inherits the properties of its parent class.

Coding Example:

What we did here:

iOS Example:

UIButton class inherits from UIView thus is able to access its properties like backgroundColor, frame, etc.

Polymorphism:
Polymorphism is combination of two words first is “poly” means many and second is “morph” means form. So Polymorphism describe us, A thing or object have many form is called Polymorphism.

Example:- A Person.

Conclusion
Finally we can say Objected Oriented Programming is the powerful and backbone of any programming language. And very useful to solve very big problem. I hope you will like this. 😊