Object oriented programming

Vechicle class

Classes are a fundamental part of object-oriented programming. They allow variables and methods to be isolated to specific objects instead of being accessible by all parts of the program. This encapsulation of data protects each class from changes in other parts of the program. By using classes, developers can create structured programs with source code that can be easily modified.

The class is one of the defining ideas of object-oriented programming. Among the important ideas about classes are:

A class can have subclasses that can inherit all or some of the characteristics of the class. In relation to each subclass, the class becomes the superclass.

Subclasses can also define their own methods and variables that are not part of their superclass.

The structure of a class and its subclasses is called the class hierarchy.

IMPORTANT: Objects are pass by reference. NOT BY VALUE. Many developers makes mistakes on passing objects to functions and other classes.

Objects are pass by reference.

Principles of OOPs :

All the programming languages supporting object oriented Programming will be supporting these three main concepts:

  1. Inheritance
  2. Encapsulation
  3. Polymorphism

Inheritance :

When a class acquire the property of another class is known as inheritance. Inheritance is process of object reusability. Through inheritance, an object acquires some/all properties of another object.

Inheritance.swift

Encapsulation :

Wrapping up data member and method together into a single unit (i.e. Class) is called Encapsulation. Encapsulation means hiding the internal details of an object, i.e. how an object does something. Hide the data for security such as making the variables as private, and expose the property to access the private data which would be public.

  • Everyone knows how to access it.
  • Can be easily used regardless of implementation details.
  • There shouldn’t any side effects of the code, to the rest of the application.

Polymorphism :

Polymorphism means to process objects differently based on their data type. Polymorphism is where the method to be invoked is determined at runtime based on the type of the object. This is a situation that results when you have one class inheriting from another and overriding a particular method. However, in a normal inheritance tree, you don’t have to override any methods and therefore not all method calls have to be polymorphic.

  • Overloading in simple words means two methods having same method name but takes different input parameters. This called static because, which method to be invoked will be decided at the time of compilation
  • Overriding means a derived class is implementing a method of its super class.
Polymorphism.swift

Data abstraction:

Data abstraction refers to, providing only essential information to the outside world and hiding their background details, i.e., to represent the needed information in program without presenting the details.

If you enjoyed reading this post, please share and recommend it so others can find it 💚💚💚💚💚💚 !!!!

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Abhimuralidharan

Abhimuralidharan

iOS and tvOS developer, dreamer, photographer 🤨