You are on page 1of 5

Introduction to Object Oriented Programming

Objectives:
Enumerate the different programming paradigms and differentiate object oriented programming from the rest of them Define object oriented programming Familiarize the students on the concepts of objects and classes

Introduction
The fundamental idea about object oriented programming is to represent real world problems in terms of objects. For example, given a programming task, rather solving the said problem in a conventional way, that is identifying the computing task or the solution and then translating that solution into line of codes and instructions, the object oriented paradigm aims to find and identify objects. These objects are entities that have behaviors, hold information and can interact with one another. The set of objects are used to model the problem at hand. What Are The Different Programming Paradigms Object oriented programming is one of the paradigm commonly used today. The other paradigms are imperative, applicative and rule based.

Applicative programming. The step-by-step execution of the command are given emphasis in this
model. A program is composed of a sequence of commands and the execution of the commands causes the computer to change the value or one or more locations in the memory.

Applicative programming. Programming task is represented by the mathematical function that the
problem represents.

Rule-based programming. The presence of an enabling condition is checked, and when present, an
appropriate action will be performed.

Object oriented programming. Object oriented programming uses objects that has data fields and
methods together with their interaction. Object Oriented Programming In Depth In an object oriented programming, a software system is seen as a community of objects that cooperated with each other by passing messages in solving a problem.

A typical object oriented language such as Java provides support for the following objectoriented concepts: Objects and Classes Inheritance Polymorphism and Dynamic binding OOP models the way humans solve a particular problem in its problem-solving techniques. Therefore, an object oriented program is structured as community of interacting agents called objects. Each object provides a service or performs an action that is used by other members of the community. What Exactly is an Object? Objects are the fundamental part of an object oriented program. According to Merriam-Webster dictionary, an object is: Something material that may be perceived by the senses; something mental or physical toward which thought, feeling or action is directed. The first part of the definition relates to physical being. These are things that we can see and touch and occupies space. Taking for example, a enrollment system, some example of physical objects that typically will take part of the system are: The student or enrollees. The professors that will teach the students The buildings in which the classroom of a particular subject will be conducted.

Software objects are modeled after real-world objects in that they too have state and behavior. The second part of the definition pertains to something mental. There are a great number of conceptual objects that play important roles in a given scenario. Given the enrollment system, some of them can be: The courses that students will attend The department that faculty works for The degrees that student receive

Even though we cannot see, hear, touch, taste or smell them, conceptual objects are every bit as important as physical objects. Defining a software object: A software object is a software construct that bundles together data (state) and functions (behavior) which, taken together, represent an abstraction of a real-world (physical or conceptual) object.

An object is also known as an instance. An instance refers to a particular object. For e.g. Toyota is an instance of a car. Gel is an instance of a professor. Data/State/Attributes Again, taking the enrollment system as an example, if we wish to record information about a student, some of them will be: Students name Student ID Students birthday Students address For a course, we might record: Course code The course name List of professors who have been approved to teach OOP In nomenclature, the data elements used to describe an object are referred to as the objects attribute. Behavior/Operations/Methods Again, revisiting the two objects student and course, a students behaviors might include: Enrolling a course Dropping a course Choosing a major field of study Telling you his or her GPA

It is a bit harder to think of an inanimate, conceptual object like course as having behavior, but if you will imagine a course to be a living thing, a courses behavior might be: Permitting a student to register Determining whether or not a given student is already registered Telling you what its prerequisite courses are Telling you how many credit hours it is worth

When we talk about software objects specifically, we define an objects behaviors, also known as its operations, as both the things that an object does to access its data (attributes) and the things that an object does to maintain/modify its data. Messages Messages are the communication mechanisms between objects. For example, when object Student invokes a method of object Course, Student is sending a message to object Course. Object Courses response is defined by its true value.

public class Payroll { String name; Person p = new Person(); String name = p.setName("Joe"); //codes are here String y = p.getName(); }

The Payroll object is sending a message to a Person object, with the purpose of retrieving the name via the getName method. Classes A class is a blueprint of an object. A class is an abstraction describing a common features of all members in a group of similar objects. For example, a class called student could be used to describe all student objects recognized by the enrollment system. A class defines: The data structure (names and types of attributes) needed to define an object belonging to that class The operation (methods) to be performed by such objects: specifically what these operations are, how an object belonging to that class is formally called upon to perform them and what behind the scenes things an object has to do to actually carry them out. The student class might be defined to have the following attributes which means that each and every student object must have the same attributes. Attribute Name name studentId birthdate address major gpa advisor courseLoad transcript (Java) Data type String String Date String String Float ?? ?? ??

In terms of operation (methods), the student class might define these methods to follow: registerForCourse dropCourse chooseMajor changeAdvisor printTranscript

Class diagram for student Take note that an object can only do those things for which methods have been defined by the objects class. So, an important aspect of successfully designing an object is making sure to anticipate all of the behaviors it will need in order to carry out its mission within the system. Instantiation The term instantiation is used to refer to the process by which an object is created/constructed based upon a class definition. Classes can be differentiated from objects, then as follows: A class defines the attributes names and data types that all objects belonging to the class must possess and the methods that all objects belonging to the class must be able to perform, and can be thought of as an empty template. An object, is a filled-in template to which attribute values have been provided.

Encapsulation Packaging an objects attributes and behavior (methods) is called encapsulation. Encapsulating related attributes and methods into a neat software bundle is a powerful idea that provides two benefits to developers: Modularity: The source code for an object can be written and maintained independently of the source code for other objects. Objects can easily be passed around in the system. Information-hiding: An object has a public interface that the other objects can use to communicate with it.

You might also like