You are on page 1of 5

Understanding Object-Oriented

Programming Concepts
Ray Klurnp, Member, IEEE

characteristics and knowledge and perform speeific tasks


Abstract-Most power engineering students these days have using those characteristics and knowledge. Expressed
had at least a casual introduction to computer programming another way, 00P developers build systems from building
concepts. Specifically, they have become functionally fluent in
blocks that possess both data and methods for working with
one or more programming languages and can use their
knowledge of basic syntax to write simple programs that
that data. These building blocks are called objects.
perform some desired task. Some students may also have had Developers of technical software can benefit profoundly
the opportunity to learn basic software design concepts, such as from using an 00P approach. They can create software that
the benefits of top-down design and the practice and virtues of offers far greater flexibility and extensibility than what they
programming in a modular fashion using a structured could achieve using a purely procedure-based design.
programming approach. However, fewer students have been
Moreover, they can incorporate components developed by
exposed to the theory and practice of object-oriented software
development. Understanding object-oriented programming other programmers to add fhnetionality to their own projects,
concepts requires that the student undergo a paradigm shift. freeing them from having to implement features that have
The student must move from thinking about modeling systems already been realized. In fat< 00P offers an unprecedented
and problems in terms of the @“ens that must be performed to degree of sofhvare reusability, a tremendous advantage for
thinking about the objects that must interact with each other to those that must model large, cliverse engineering systems.
perform those actions. Successfully navigating this change in
Power system engineers are quite familiar with modeling
thought is not a trivial undertaking, but the rewards of doing so
can be tremendous. This presentation provides a brief large, diverse engineering systems. The number of different
introduction to the concepts and benefits of the object-oriented components that comprise a systeu coupled with the great
approach and explains why power engineering students may variety of models, attributes, and fimctions for those
benefit greatly from a more formal introduction to the topic components, makes power system analysis a prime candidate
for 00P-based software development. This argument holds
Iisdex Terms-Object Oriented Programming, Object for managing and performing calculations on power system
Oriented Methods, Software Reusability, Power System
da~ but it is particularly relevant when it comes to
Modeling, Power Engineering Education
presenting that data to the user. Effective communication of
I. INTRODUCTION power system characteristics and trends to the user requires
providing poignant visualization tools accessible through a
o bject-otiented programming, or 00P, is a software
development philosophy that has revolutionized the art
and practice of writing computer applications. Regardless of
convenient graphical user interface. The only praetieal way
to fashion such technology is to take an 00P approach to
sofhvare development. Thus, it is crucial that power
the target discipline, programmers who work on sizable,
engineering students be formally exposed to the ideas,
multi-faceted software usually approach such problems from
implementatio~ and benefits of object-oriented design.
an 00P mindset. The 00P approach borrows the ideas of
This discussion provides a “crash course” in these ideas in
moduki.rity, smooth flow of control, and proeedure-based
the hopes of spurring a more formal classroom presentation of
implementation of subtasks from its ideological and equally
the topic for power engineering students. It outlines the
revolutionary predecessor, structured programming.
concepts that underlie 00P, i(iendfies the primary advantages
However, 00P supplements these ideas with an emphasis on
of the approach, and recommends ways to introduce 00P to
conceptualizing systems in terms of the components that must
power engineering students.
work together to achieve the required fimctionality and
behaviors. In other words, whereas a structured programmer
II. CORNERSTONESOF OBJECT~RIENTEDPROGRAMMING
strives to implement a system by coding the system’s tasks as
a set of procedures and functions, the 00P developer The central ideas of 00P are encapsulation, inheritance,
implements a system by modeling its components. Modeling information hiding, data abt.ractiom and polymorphism.
components means creating objects that exhibit certain Each of these emxepts helps give the objeet+riented strategy
considerable advantages over the more traditional structured
programming approach.
Ray Klumpis with PowerWorldCorporatiq Urbanq IL 60544 USA(e-
maikray@,powerworldcom).

0-7803-7173-9/01/$10.00 © 2001 IEEE 0-7803-7031-7/01/$10.00


1070 (C) 2001 IEEE
A. Encapsulation unique behaviom In other words, the class B definition
Designing an object-oriented model involves defining a set includes both the methods of class A and additional methods
of classes. A ckr,ss is a template from which objects are used to perform different tasks. Furthermore, although the
created. The template, or blueprin~ provided by a class subclass inherits all the behaviors of the superclass, it can
specifies a set of data and mefhoa!s that all objects created implement the behaviors in dillerent ways. In other words,
according to its specifications will contain. In other words, the methods of class B can override the same-named methods
the class definition identifies the characteristics and behaviors of class A to perform an identical task in a different way.
of objects created from it. The term encapsulation simply For example, consider a system for which the designer has
describes the class’s function of bundling data and methods to defined a class called Generator. A generator is a machine
work with that data into a single data structure. This differs that converts mechanical energ to electrical energy,
from the role of the familiar record data structure, which However, a few different types, or classes, of electric power
contains data fields but no prescriptions for retrieving, generators currently find use. For example, both combustion
setting, or using the data. turbines and coal-fired units are generators in that they
Students often confhse the terms class and object. It is inherit the ability to generate electricity from mechanical
important to distinguish the class, which should be viewed as energy. Suppose, theu that the developer defines two classes,
the template, blueprin~ or prescription, from the objec~ CombustionTurbine and CoalFired, thatextend, or inherit
which is the specific “widget” built according to that from class Generator. Objects of all three classes might
template, blueprint or prescription. For example, share attributes such as the amount of power they are
FordEscort is a class of automobile, generating, the maximum and minimum amount of power
myl 988GrayFordEscortThat.NeedsNwTi~s is a specific they can generate, their fuel and operating costs, physical
object built according to that class blueprint. location, and plant name. They may also each have a method
A disciplined object-oriented approach involves developing called produceElectricity whose job is to provide an electrical
a program by designing its component classes and specifying output. However, the definition for class
the manner in which those classes will interact. This strategy CombustionTurbine’s produeeElectricity method will difTer
differs from the slandard structured approach. The from that of class CoalFhed, even though both inherit the
traditional structured approach views a system in terms of the ability to produce electricity from their common superclass,
tasks it performs and thus strives to code the functions and Generator. Both subclasses actually are types of generators,
procedures that implement those tasks. The building blocks and so both know what it means to produce electricity,
of such programs are its functions, and the programmer However, they do so in different ways. Agaim this sort of
develops them by focusing on the verbs of the problem relationship, in which types of objects exhibit similar sets of
statement [1]. An object-oriented designer focuses on the behaviors but act in different ways, ve~ closely parallels
types of objecls that need to interact to perform a function. In physical reality.
other words, there is a heavy emphasis on the nouns of the C. Data Abstraction
problem statement which the designer translates into the
A basic tenet of the structured programming approach is
program’s classes. Objects created according to these classes
that programs should be constructed in a top-down manner.
perform their tasks using the methods packaged within them,
If one considers that the physical world consists not of The topdown approack also called stepwise refinement,
suggests developing algorithms in a series of steps that move
independent actions but rather of actors that perform actions,
from a very general statement of the desired behavior to an
it becomes clear that developing programs from an object-
increasingly specific view of the task’s implementation
oriented pcrqxctive more closely parallels real physical
details. The topdown approach also finds application in
systems. Software classes, like physical entities, encapsulate
00P circles, but in a slightly different guise. In developing
both data (characteristics) and methods (behaviors).
inheritance hierarchies, object-oriented developers factor out
B. Inheritance the most rudimentary shared attributes and behaviors and
Classes can extend the definitions provided by other ascribe them to a root superclass, which may be considered
classes. Specifically, they can inherit the data and methods of the ultimate superclass for the class hierarchy. This ultimate
another class. For example, suppose class B extends, or superclass provides the most abstract interpretation of what it
inherits from, class A. Then, class A is called the superclass, means for an object to be of a certain eatego~. In fact most
and class B is called the subchzw. An object created object-oriented languages allow programmers to define such
according to the subclass definition has all the characteristics superclasses explicitly as being abstract. One cannot create
prescribed by the superclass detinitiok but it also can specific objects from abstract classes, because they are too
supplement these data with additional attributes unique to vague to serve as a blueprint for something tangible. For
itself. Likewise, an instance of class B has all the methods, or example, consider the previous example involving the
behaviors, prescribed by class & but it also can add its own FordEscort class. Its superclass might be the more abstract

0-7803-7173-9/01/$10.00 © 2001 IEEE 1071


0-7803-7031-7/01/$10.00 (C) 2001 IEEE
class Automobile. Class Automobile is far too vague to type of the object being considered.
create a definitive representation of it. However, FordEscort, For example, consider this snipet of Java code that
which itself is (in other words, inherits data and methods implements precisely the scenario described above:
from) an automobile, has a realizable blueprint from which PSObj ect psObj [] = new PSObj ect [2] ;
one can create specific objects. Similarly, depending on the PSObj ect p;
Bus b= new Buso;
level of detail being targeted in developing the model, class Load 1 = new Load( 1;
Generator may be tm vague to create an object fkom i~ psobj [0] = b;
psObj [l] = 1;
because it is unclear how a specific instance of Generator for (int i = O; L < psObj length; i++)
will produce electricity. Generator is thus an abstract class. System. out. println(psObj [01 .getldentifier( ));
More specific descendants of Generator define how they
The lone instruction of the for loop will call a dilYerent
produce electricity and thus allow the programmer to create
version of getIdentier during each of the two passes through
objects from them. This practice of creating a design from
the loop. When i = O, psObj[i] is Bus object and so the
general definitions of common attributes and behaviors to
getIdentifier method of Bus will be called. However, when i
more specific classes that add characteristics and specific
= 1, psObj[i] is a Load object which means that the
implementations is called data abstraction. Data abstraction
getIdentitier method of Load will be called. The
helps the developer categorize components of systems
polymorphic mture of 00P languages provides this behavior
according to their form and function and thus unveils a
automatically.
composite picture of how the different actors in a system
Without polymorphism, the programmer would have to
interrelate. Moreover, data abstraction helps a system take
employ Z~ statements or switch logic to test the type of the
more complete advantage of one of the most powerfid features
currently active object. This alternative would clearly be
of object-oriented desigq polymorphism.
difficult to maintain as the size and diversity of the modeled
D. Polymorphism system changes. Polymorphism allows the developer to
Polymorphism may be considered the “great enabler” of process objects of related classes in a very general way by
00P. Polymorphism enables programmers to manipulate focusing on class similarities. Polymorphism accommodates
subclass objects using superclass references. This advantage implementation differences by automatically dispatching
may seem insignificant until one considers that mom physical commands to the appropriate methods at execution time.
systems consist of collections of objects. A power Systew for This allows code to be far more flexible and extensible.
example, consists of a collection of components that may, in a E. Information Hiding
ve~ general sense, be considered objects of some abstract
Classes encapsulate data and methods into a single data
class called PowerSystemObject. Looked at more closely,
structure. Subclasses inherit these data and methods from
each object can be said to hail from a more specitic subclass
superclasses, and subclasses and superclasses can thus be said
of PowerSystemObject. There are Bus objects, Generator
to be related to each other. Suppose class A and class B have
objects, TransmissionLhe objects, Load objects, and so on.
been defined to have entirely ditTerent inheritance trees; in
Each of these subclasses may actually have their own
other words, class A and B are not related to each other
subclasses descend from them. All PowerSystemObject
through inheritance. An object of class A can access the data
instances share common attributes and methods. They each
and methods of class B, and vice-versa. However, it maybe a
have an identifier by which system operators reference them.
good idea to limit such outside access. An object of class A
They each have a geographic location. They each have a
may not know the proper way to set the value of a particular
status. They each can report their identifier, geographic
attribute of an object of class B, for example, and may thus uy
location, and status to other objects that request such
to set it to an improper value. For this reasou object-oriented
information from theu but the manner in which they do so
designs usually prescribe class data to be kept private and to
likely will differ among different classes. For example,
be accessed only through publicly accessible methods, The
suppose the method that reports a PowerSystemObjeet’s
publicly accessible methods of a class establish the interface
identifier is called getIdentifier. When a Bus object
by which objects of a class interact with the outside world.
communicates its status to another objm it might add the
Non-related objects have no access to the object’s private
string “Bus” before its identifier, whereas a Load object
fields and methods, but they can communicate using the
might add the string “Load”. Thus, the definition of
public methods that comprise the interf’.
gefldent.ifier for Bus objects diflers from the definition of This public-versus-private scope concept also mirrors
getIdentifier for Load objects. Interestingly, however, if one physical reality quite well. Engineering analyses of
iterates through this collection using a generic interconnected systems tend to treat even ve~ complex
PowerSystemObject reference and calls getIdentifier from components as “black boxes” that connect to the rest of the
the context of this reference, the computer will locate and system only at spedc terminals. Information hiding
invoke the version of getidentitier that is specific to the actual provides object-oriented developers a particularly convenient

0-7803-7173-9/01/$10.00 © 2001 IEEE 1072


0-7803-7031-7/01/$10.00 (C) 2001 IEEE
way to comect “black boxes” into their own sofhvare systems. design models an efficient boss+mployee relationship, the
This makes the use of third-party software components, even boss doesn’t micro-manage the employee’s actions, and the
those developed in a different programming language, both employee, eschewing even an executive surnnmy, fulfills its
possible and safe. It also allows modelers of physical systems responsibility and provides notilng more than the result it
to substitute and test difTerent models within the same was programmed to perform.
software platform with minimal impact on peripheral code. 00P provides the tools to model the cogs that comprise the
Here agai% the 00P approach graces software systems with machine. When a better cog comes along, the developer
tremendous extensibility and flexibility, simply swaps the parts and restarts the machine. Software
models thus become extremely versatile and customizable.
III. ADVANTAGESOF OBJECT-ORIENTEDDESIGN
B. Reuse of Code and Interoperahilify
The previous section has already identified the key benefits
The fact that one class (the subclass) can inherit data and
of object-oriented software design. This section places these
methods from another class (the superclass) creates
advantages into two categories: heightened extensibility
tremendous opportunity for code reuse. Some methods of the
through closer modeling of physical systems, and
subclass may be identical to those of the superclass; thus, no
unprecedented code reusability.
new code need be written. When a subclass method does
A. Closer Modeling of the Physical World override a superclass method, it is common for the subclass
Object-oriented development models systems in terms of method to use the superclass’s implementation and simply
actors rather than isolated actions. Newton’s First Law of embellish it by performing additional tasks. Agai~ rather
Motion predicts that objects at rest remain at rest unless acted than recode the superclass impIementatio~ most object-
upon by another object. Object-oriented design respects this oriented languages simply allow the subclass to reference the
behavior. Objects, which possess certain characteristics superclass’s implementation as part of its own
referred to as their data, use their set of behaviors, referred to implementation. In a large proje@ this represents a
as their methods, to act upon other objects, thus causing some tremendous savings in the quantity of code that must be
change of state. In strum function-centric programming, written.
the action that causes the state change is like a dew ex The concept of a class as describing a machine cog or black
machina, appearing without anteceden~ introduced simply by box also means that software authors need not work in
virtual of the instruction stored in a computer register. isolation. They can draw upon the work of other class
Object-oriented sotlware models clar@ the initiator of the authors to borrow functionality for their own projects. A sort
action and thus more clearly show the relationship between of cottage industry has developed around the idea that
system components. This makes object+riented models sofhvare should be constructed as a network of interconnected
easier to understan~ docurnen~ and maintain. components that communicate with each other along publicly
One of the human intellect’s greatest gifts is the ability to defined interfaces. These interfaces consist of the
summarize. A primary tool of mnmmization is the ability to components’ publicly defined data and methods and provide
categorize groups of related objects together according to the mechanism by which they can be plugged into a system
their shared attributes and behaviors. Once categorize and communicate with that system’s objects. This notion of
samedisscd objects can be collected together in some easily software development is the impetus behind such technologies
accessible location and used more conveniently to perform Common Object Request Broker &chitecture (CORBA),
some task. 00P’s principles of inheritance and Sun’s Java Servlets and Javia Beans, and Microsoft
polymorphism enable an identical process. Groups of similar Corporation’s Common Object Model (COM), Distributed
classes are related through inheritance. They may be stored Common Object Model (DCOM), and .NET technologies.
in a collection such as an array or vector and referenced using Many of these technologies am network-aware, enabIing
a generic handle that can refer to objects of all such classes. object-oriented developers to import functionality that resides
Each object stored in this collection knows how to perform its on remote application servers into their own applications in
tasks in its own unique way and will do so reliably when real time. The encapsulation of data and methods and the
called upon. ability to craft welldefined intetii~ces through exposing only
This observation begs a related point: those using this certain data and methods makes this interoperability of
collection of objects need not worry about how each object resources possible.
does what it is designed to do. Each object was built horn a
class blueprint that completely specifies the details of its IV. CLASSROOM RECOMMENDATIONS

behavior. The object doesn’t need to share those details with Much power engineering research particularly research
those who call upon it; it merely needs to provide a seMce. that focuses on systems analysis, is performed on PCs and
The entity requiring the service delegates the role to the workstations rather than lab benches. Thus, both
object without worrying about the details. Object-oriented undergraduate and graduate power engineering courses tend

0-7803-7173-9/01/$10.00 © 2001 IEEE 1073

0-7803-7031-7/01/$10.00 (C) 2001 IEEE


to devote significant time to teaching algorithms and @ = ~ SO* deVC@IX * Mi~AuI~M ~~+ N** W
between1996 and 1998. He has workedas a power systems eonauhant and
numerical methods. This training provides vital preparation
soihvare &vehper at PowerWorldCorporadoain UrbamAK since1998. Hw
for students who may be asked to write software modules to researehinterestsinclu&vottagestabititya.==ment computational
t.cehoique%
model a particular power or mechanical system later in their and data vkuabtiom Dr. Klumpalso teaehescdtegeeaursesin annputer
science,mdhemad~ aod electricalonginmringand considersteachingone of
careers. Usually, the training is delivered in a language- M favoti ~titi.
independent manner and focuses instead on how the
algorithms and methods perform a particular calculation.
This is as it should be. To force a particular language on
students as they attempt to understand how the implicit
trapezoidal method integrates systems of differential
equations would only obscure the important lessons.
The tremendous benefits of (X)P - reusability,
extensibility, and interoperability – should not go unnoticed
by power engineering students. Although much legacy code
exists that predates the advent of 00P, these systems will
eventually be replaced by software employing more modem
approaches. Moreover, even deeply entrenched elder
applications are now being ported to new hardware, where
modem software middlemen typically provide an object-
oriented communication interface to time-tested functions.
Thus, power engineering students would benefit greatly from
a formal discussion of 00P concepts.
However, the same restraint that is exercised when
discussing algorithms and numerical methods should be
exercised when discussing 00P. Specifically, the lessons
should not require students to use a specific language or
technology. Besides obfuscating the important concepts of
00P, dictating a language choice tempts obsolescence. This
is particularly true in the fast-pac4 mercurial world of
software technology.
Instea& stndents should be asked to develop a suite of
classes that together model a particular physical system. For
example, a course on power systems analysis might pose an
assignment where students are asked to create a class
framework for modeling loads, buses, generatom, areas, lines,
shunts, areas, and zones. Their design should start from an
abstract base class that encapsulates the data and methods
common to all power system elements. Each subclass shotid
then supplement and customize the attributes and behaviors
of their ancestor classes to implement their own specitic tasks
and relationships. They should also be given a simple
exercise in polymorphism in which they use pseudocode to
demonstrate how objects created from their class fi-amework
can be manipulated in a very general way using superclass
references. Such lessons should help students navigate, as
well as appreciate, the shift from fimction-centric to object-
centric coding.

V.REFERENCES
[1] H. M.DeitelandP. J. Deite~JOVCI
How To Program, 3d d New York:
Prentice
Hatl, 1999,p. 326.

VI. BIOORAPHY
Ray Klump(M’1991) received his PhD. fromthe Universityof lltiiis at
Urbana-Champaign
in October,2000. He workedas a power-@mMengineer

0-7803-7173-9/01/$10.00 © 2001 IEEE 1074


0-7803-7031-7/01/$10.00 (C) 2001 IEEE

You might also like