본문 바로가기

개발

Introduction to Object-oriented Programming (OOP)

Introduction to Object-oriented Programming (OOP)

Why do we need to program?
Technology is part of our life. The world is changing daily and everything is getting automated. Learn to program is the creative way we can take our ideas to the next level and express solutions to society. By designing programs, we learn several abilities like critical reading, analytical thinking and create synthesis. The programmer defines the problem, plans a solution, codes the program, test the proposal and documents the features. But we can't program all the solutions with the same method, that's why programming paradigms appears.

Overview of Programming Paradigms
According to Vasappanavara, a programming paradigm "it is the manner in which programming elements such as functions, objects and variables are exploited to produce the desired output". It is important to understand that programming paradigms are not programming languages.

The following are typical examples of programming paradigms (according to Bhave):

What is Object-oriented Programming (OOP)?
The object-oriented is a programming paradigm where the program logic and data are weaved. As stated by Phil Ballard, it is a way of conceptualizing a program's data into discrete "things" referred to as objects, each having its own properties and methods.

Let's see an example. Suppose your friend is a bank manager and he wants you to help improving their system. The first object you might design is the general-purpose Account. The Account object has properties and methods. For each client your friend's bank have, you would have to create an Account object.

Characteristics
As follows the most important features of object-oriented programming:

Encapsulation. Capability to hide data and instructions inside an object.
Inheritance. Ability to create one object from another.
Polymorphism. The design of new classes is based on a single class.
Message Passing. It is the way objects communicate with each other.
Garbage Collection. Automatic memory management that destroys objects that are no longer in use by the program.

Benefits
As follows some benefits of using object-oriented programming:

Re-usability. You can write a program using a previous developed code.
Code Sharing. You are able to standardize the way your are programming with your colleagues.
Rapid Modeling. You can prototype the classes and their interaction through a diagram.

Drawbacks
As follows the disadvantages of using object-oriented programming:

Size. Are larger than other programs, consuming more memory and disk space.
Effort. Require a lot of work to create, including the diagramming on the planning phase and the coding on the execution phase.

Basic Concepts
Class
Basic template that specifies the properties and behaviours of something (real life or abstract).

Object
Particular instance of a class that responds consequently to events.

Attribute
Characteristics of the class. Often called instance variables.

Method
Algorithm associate to an class that represent a thing that the object does.

Subclass
Class based on another class.

Inheritance
Process where the subclass gets the attributes and methods from its parent class.

Interface
Specific template that enforces certain attributes and methods of a class.

Package
Namespace that organizes a set of related classes and interfaces.

Event
Alert the application when there is a state change of the object.