Intro to computers and programming

Receive aemail containing the next unit.

Introduction to Object Oriented Programming

Principles of Object Oriented Programming

Object Oriented Programming (OOP) is a programming paradigm that provides a means of structuring programs so that properties and behaviors are bundled into individual objects. It is a way to write programs using classes, which in turn are templates for objects.

What is Object Oriented Programming?

In OOP, each object is an instance of a class. Objects are entities that have attributes (properties) and behaviors (methods). For example, a car can be an object. It has attributes like color, model, and brand, and behaviors like start, stop, and accelerate.

Four Principles of OOP

There are four fundamental principles in OOP: Abstraction, Encapsulation, Inheritance, and Polymorphism.

Abstraction

Abstraction is the process of hiding the complex details and showing only the essential features of a particular object or concept. In OOP, an abstract class can be used to define a base class with methods that the derived classes would implement.

Encapsulation

Encapsulation is the process of bundling the data and the methods that operate on that data into a single unit, i.e., class. It is a protective shield that prevents the data from being accessed by the code outside this shield.

Inheritance

Inheritance is a mechanism in which one class acquires the properties (methods and fields) of another class. With the use of inheritance, information is made manageable in a hierarchical order. The class which inherits the properties of another class is known as the subclass, and the class whose properties are inherited is known as the superclass.

Polymorphism

Polymorphism is the ability of an object to take on many forms. The most common use of polymorphism in OOP occurs when a parent class reference is used to refer to a child class object. It allows us to perform a single action in different ways.

Benefits and Drawbacks of OOP

The main advantage of OOP is that it simplifies software development and maintenance by providing some concepts:

  • Objects can also be reused within an across applications. The reuse of software also lowers the cost of development. More effort is put into the object-oriented analysis and design, which lowers the overall cost of development.
  • It makes software easier to maintain. Since the design is modular, part of the system can be updated in case of issues without a need to make large-scale changes.
  • Reuse also enables faster development. Object-oriented programming languages come with rich libraries of objects, and code developed during projects is also reusable in future projects.

However, OOP can be seen as more complex to understand and write than procedural code, and it can be less efficient and slower in terms of execution speed.

By understanding these principles, you can start to see the world in terms of objects. This is a key step in becoming a successful object-oriented programmer.