Object-oriented programming
was created with coders and designers in mind.
It has expanded to many different languages as it has proven to be
efficient and sustainable among the options that are available today. The main concepts of encapsulation, abstraction,
inheritance and polymorphism are the core principles this idea. Building large structures into small
manageable objects with multiple capabilities is the valued philosophy of
object-oriented programming. Since its
early days at the Massachusetts Institute of Technology, it has become an
industry standard and will remain relevant for years to come [1].
Object-oriented programming
and design is a topic that covers many of the modern languages we use
today. The focus of object-oriented
design, in my opinion, is to create forms of data to be reused. Java has the slogan “write once, run
anywhere” which helps my definition.
Java is a class-based language, introduced in 1995, that is one of the
better examples of being able to perform all the ideas of object oriented
programming [1]. To define a class with
variables and methods means you can then create an object of that class to use
in your programming. It can be used in
the current program and if you need to reuse the concept, it can be
reincorporated into another program without having to be rewritten. That is the beauty of object-objected
programming and design. It places
emphasis on the coder to feature the abilities of encapsulation, abstraction,
inheritance and polymorphism for optimization of the language [2]. These are coding principles specifically for
this type of programming that I will discuss more later on in detail. The term object-oriented began in the early
1960’s in MIT with the development of the LISP language. I would prefer the languages of COBOL, Visual
Basic and Java as examples of implementation since I have more experience with
them personally. I had a course devoted
to each while enrolled at Frostburg State University as an undergraduate
student. COBOL stands for common
business oriented language actually.
After appearing in 1959 after being generated with government
assistance, COBOL is thought of as a procedural language by many [3]. It can be used to generate forms and report
on data related to business interactions.
However with the ability to create variables and invoke classes, I will
use it as an early example of an object-oriented one. Visual Basic is considered an event-driven
language. Primarily user create a
graphical user interface and then decides what can happen once certain events
are triggered. Events can be defined as
the user interaction with the form such as once the mouse is clicked or a
button is selected. Whenever something
happens the application should have a response.
Again, I will use it to show some of the OO capabilities that can be
found in that as well. Also let me
introduce some terms that I will use throughout my writing. Variables are individual allocations of memory
of a certain data type which can have value assign to them. Data type are the form of the
information. Some of the common examples
are integers for numbers, chars for individual alphanumeric characters, string
for multiple alphanumeric characters and Boolean for true or false value also
known as either the one or zero bit. Methods or
procedures are a series of commands or instructions that will take place once it
is called or activated. Classes are
container elements of some combination of the previous two programming concepts
that can then be treated as an object.
It is important to know these definitions before we go much further on
the nature of this topic. From an
expert’s point of view this may be fundamental but I will try to write from the
perspective of a novice so it may be appreciated by a wider audience.
One of the first components I
will discuss is encapsulation. Some may
call encapsulation the process of concealing parts of your program. I prefer the slightly lighter view of
building capabilities into your objects.
It can be as simple as assigning a value to a variable. Instead of consistently working with a
constant value, you can define a place holder to use throughout your
program. As I said, that is the simpler
view that can be performed in COBOL, Visual Basic and Java but each does it in
a different way. COBOL uses the pic
keyword to assign value to variables in its data division [4]. In visual basic coders use the dim keyword to
name the variable and then what type it is.
Java you have to give the type then its name. For VB and java you can use the ‘=’ operator
to place a value upon it. The more
complex side is to create class with its own methods to use. In java it is common to use
encapsulation. Using class objects to
perform specific tasks is a major component to the language. Creating the objects of your own volition is
the more hands on approach. Within the
class you can identify variables and methods which it will use. There is another aspect of the constructor to
deal with as well. A constructor is
called when the object is first instantiated using the new keyword. Constructors can accept a value or not but
what happens in either instance will have to be defined by the coder. Once the object of the class is usable, you
can then interact with its variables and methods as you wish. Therefore is the main coding section, you
can use the object and refer to its contents instead of add that section of
code to the main portion. Depending on
the object this can be easier for you and would be the same without
encapsulation. For instance, you can
code a method to perform a loop. This
loop could have been created in the main source code. However, if you were to call it multiple
times, it would be relatively simpler by calling the method several times and
writing the steps and iterations of the loop once.
Abstraction, in my opinion, is
the middle step between encapsulation and inheritance. Not the middle in terms of the creation
process but it can use encapsulation to lead to inheritance though it is its
own concept. The word abstraction is the
quality of dealing with ideas rather than events. The translation is near perfect because for
programmers it is creating the skeleton of a class. The initial abstract object only incorporates
the fundamental framework of what will be used.
Reduce the object to the bare minimum that is required for it to
exist. The class can be absorbed by another
class that can then define what its variable contents would mean and its
procedures would do. You can create the
class by telling what the types of variables are and the names of the methods
only. Just the frame work is necessary
for initial processing which makes abstraction unique. The ‘hello world’ example is shapes. You can model an abstract class or interface
of shape with variables for height and length and then methods of draw,
perimeter and area. The idea is that all
shapes have these properties but they will be defined differently. The coder can design classes like circle,
square, rectangle and triangle that share these same attributes though they are
not handled identically. Each can assign
height and length but how they are formed using draw and how the area of the
shape is calculated will have to be defined in each class while they use the
same name or ‘area’. Area for circle is
half length multiplied by pi, square can be length to the power of two,
rectangle can be length multiplied by height and triangle can be half the
length multiplied by height. This is an
example of abstraction only because the theoretical parent class has nothing
defined in it. If we were to define any of
the parameters in the parent class, it would have to be redefined by the child class which is not
optimal to the concept. For shape there
are no universal properties accept the names of its contents not the values.
Abstraction leads to the topic
of inheritance. Inheritance has parent
and child classes. The parent class will
be defined and then the child can inherit those capabilities and add to them if
it needs to. Inheritance lends itself
more to the idea of a hierarchal structure than that of abstraction. Though the two are very similar, the idea
behind inheritance is opening the door to use some of the predefined attributes
of the parent class. Usually in
inheritance that entire object will not have to be redefine. Users can do this in two ways. One is to inherit the parent class and not
redefine a specific detail. This would
confirm that you wanted to use the parent definition for the child because some
of its traits can be carried over.
Another in java is to call the parent in the child using the super
constructor option. In contrast to the
shape example, I will try to discuss vehicle.
Now vehicle in these terms will refer to an automobile. The vehicle will have four wheels, take gas,
have glass windows and require one driver.
Those traits can all be passed to children coded as sedan, truck, van
and sports car. Within the children will
holds information like top speed, number of passengers, number of doors and
off-road capability to name just a few attributes. Now those can be variables of the parent that
are not defined or only belong to each child.
That would be the choice of the coder.
Either will suffice. Those are
examples of variables. Some methods
would be to drive forward, reverse, turn and park. If the designer wanted to be specific I
supposed the size of the vehicle could be incorporated into park so each child
would define it by the type of car it is.
Moving the vehicle can be defined in the parent and still called by the
child.
Sharing certain properties transitions
to the subject of polymorphism.
Polymorphism describes similar things existing at the same time. That can mean variables, methods or even
class objects. Variable and methods can
be determined by scope. Scope entails
range in a program where something can be used and is identifiable. For a variable to be out of range says that
it is no longer in the range of which it was instantiated. You can either recreate the variable for the
current context or see if there was another error in the coding. An example of this is to create a variable to
use within a looping algorithm. If a
variable is created in the loop itself, it can be used in the loop. Once the loop ends, the value that the
variable held will no longer be in memory.
Then the variable can be recreated with the same name and used with a
different value. Methods can show
polymorphism using the abstraction example.
Calling the draw method for each shape a similar concept. You can theoretically line up each shape
using the draw method in succession.
Rectangle draw, circle draw, triangle draw and square draw will each respond with what it is designed to do.
Though they have the same name and can be contained in the shape class,
each shape’s draw will only respond to the class that requested it. This can be confusing but if the class object
is used to identify the method then it makes it easier. Classes can have more than one object as
well. Using the inheritance example, if
I wanted to name vehicle as specific makes or models that can be done using
the same class. Instead of naming my
sedans one and two, I could name them honda_accord and toyota_corolla. In most programming languages the underscore
will have to be used connecting the two words to avoid errors. Both can be sedan and both can have some
differentiation used when assigning some values to the variables.
Object oriented programming
has really assisted designers advance coding with its definitive
properties. How encapsulation,
abstraction, inheritance and polymorphism are used brings a new significance to
programming. Building new objects with
classes that can be defined and processed as data types is remarkable. It can provide a first-hand level of control
with incomprehensible depth of the ability to create whatever you feel possible
in your imagination. Speaking as of
today, it may not be the revolutionary concept it was when it was first
introduced. The concept of its intention
has remained at the forefront of how programming is performed by professionals
and taught by professors. Since I am not
as advanced as others of this genre, I cannot expound on areas of weakness or
where improvements can be implemented.
Learning about these forms of subjects can allow the ability to compile all the informational resources within your own comprehension but execution requires a
different level of mastery to be fully functional and operational.
References
[1] https://en.wikipedia.org/wiki/Java_(programming_language)
[2] https://en.wikipedia.org/wiki/Object-oriented_programming
[3] https://en.wikipedia.org/wiki/COBOL
[4] http://cobol.404i.com/content/defining-data
[5] https://en.wikipedia.org/wiki/Visual_Basic