Login | Register
Print page
Email page

Home » Objects solid in automation

Objects solid in automation

ControlDesign.com

Object-oriented programming (OOP) was designed from scratch with modules in mind and is straightforward, flexible, and an ideal tool for creating reliable applications to manage complex tasks.

By Matt Scott, Deseret Laboratories

BY NOW, even the most hardened ladder logic devotee has heard about programming alternatives such as object-oriented programming (OOP). This technique lends itself to structured and modular software code. Modular coding can be implemented with virtually any programming language from ladder to function block, but object programming was designed from scratch with modules in mind.

This means that OOP tools and programming languages naturally lead to discrete modules or blocks of code linked together with rules that are part of OOP programming languages.

The flip side of modular programming is simple, monolithic or spaghetti-style programming. These types of programs don’t use modules but rather have all code in one continuous string. Monolithic programming skips advanced programming techniques, and goes straight for the quick fix. This often means programmers are writing code without first thinking about the overall structure of the program. This might seem to be an expeditious way to write a program, but problems often result.

A program written without a pre-defined structure can become very complex—even incomprehensible to everyone except the original programmer. Even the original programmer could become confused as the program grows more complex or when it needs to be revisited later.

Conversely, structured and modular programming requires thought and planning prior to coding. If structure and modules are desired, then OOP is an ideal tool.

Modular coding, OOP in particular, offers many advantages over monolithic code including ease of test, reuse of code, and portability to different hardware target platforms.

OOP was developed for good reasons, and, under the right circumstances, it can produce excellent results and perform tasks that are virtually impossible otherwise. With OOP, a skilled programmer can program an application in an organized manner.

It only takes one programmer to properly develop an OOP framework. That framework can then be used by other programmers. The beauty of OOP lies in its ability to manage complex tasks, its flexibility, and its efficient use of hardware.




Inside OOP
OOP is a high-level extension of the modular code concept. By building cleverly thought out, reusable modules of code, repetitive programming is avoided. Code also becomes more organized and readable.

Individual modules of code, or classes, can “inherit” each other’s contents. A child class inherits the contents of a parent class. Inherited contents can be modified by adding new code or improving old code. For example, a parent class can be written to allow a PC to exchange data with a particular PLC brand and model.

A child class also can be created for a different PLC, with the child inheriting the parent’s common functionality, while still giving the programmer a way to add hardware-specific details.

An object is an instance of a class, and it contains data and code that operates on that data. Multiple objects or modules are linked together to build programs.

As a result, objects can be linked together in a tree structure by having them contain each other’s memory addresses. Those addresses then can be followed from object to object. This functionality is called traversal. As the program traverses, each object is accessed, and the program gathers information about that object or provides services such as settings management of that object.

For example, the traversal function can be used to build a test-and-validation document for the entire program by traversing a tree of objects that contain the file name of a test-and-validation document that describes the object and its requirements. The traversal function collects all test-and-validation information in an organized fashion.

By traversing a similar tree of objects, a programmer can gather all the pertinent information describing those objects. This information can then be used to build a new program with a similar structure on another machine. This technique is known as serialization.

An entire graphical user interface (GUI) page can be transported from one hardware platform to another by serializing an object that contains a description of the GUI page.

When to OOP
OOP takes more up-front work than monolithic code, so OOP should be applied only when dictated by circumstances.

OOP systems are particularly useful when all the eventual uses and applications of a program can’t be known in advance. Some OOP languages also are suitable when a software program is needed to control a variety of hardware, for example, when a corporate-level software engineer must implement an advanced control algorithm across several plants. These facilities contain a variety of software operating systems and hardware platforms. OOP’s inherent flexibility would allow the engineer to create a base program that easily could be modified for each platform.


More content on this topic:

Free Subscriptions

Control Design Digital Edition

Access the entire print issue on-line and be notified each month via e-mail when your new issue is ready for you. Subscribe today.