Introduction to Object Oriented Programming (OOP)
OOP or Object Oriented Programming has been around for years. But many of us who have been using COBOL, TAL or C, have nothing to help us relate to this “new” approach to application development. Most of us have experience with “called modules”, libraries and functions, but not “objects” nor in how to benefit from using them. Programming languages such as Java and C++ are built on OOP concepts. If you are interested in learning those languages or using them on NonStop, you should start with the basics I have outlined here.
In this article we will take a very high level look at objects and some of their benefits.
What is OOP? Object Oriented Programming Combining code and data into “objects” that can be reused and whose internal structure is transparent to the object’s consumer.
Why use OOP?
Emphasis on data rather than procedure
Programs are divided into Objects
Data is protected and cannot normally be accessed by external functions
Objects can communicate with each other through functions
New data and functions can be easily added whenever necessary
Follows bottom-up approach
What is an object? An object can be considered a “thing” that can perform a set of related activities and has defined attributes or properties. The set of activities that the object performs and its attributes define the object’s behavior. In some ways a Cobol “called program” has some characteristics of an object. A serverclass program could be considered like an object.
What is a class? A class is simply the representation of a type of object. It is the blueprint/ plan/ template that describe the details of an object. A class is the blueprint from which the individual objects are created. Classes are composed of three things: a name, attributes or properties, and operations or methods. In some ways, the DDL definition of a request and reply is similar to some aspects of a class.
What is an object instance? An object or class instance is created when that class is used. As an example, let’s say there is a Hand object. A human has two instances of Hand, right and left. And each person has their own, unique, instances of Hand. The attributes of a specific Hand instance will vary: size, color, amount of hair, whether it is a right or left hand etc.
What is inheritance? When a class is defined, it can inherit from one or more other classes. Attributes and methods of the parent classes are inherited, much like a child inherits features from their parents. As an example, let’s start with a telephone class.
A base object – Telephone
We will create some derived classes from Telephone. They will all inherit the base class’s attributes and operation. But they can add attributes and/or operations as needed.
Cell Phone derived from Telephone
Attributes (in addition to Telephone’s)
Operations (in addition to Telephone’s)
Smart Phone derived from Cell Phone
Attributes (in addition to Cell Phone’s)
Operations (in addition to Cell Phone’s)
What is encapsulation? Wrapping a set of operations and data to simplify, protect and standardize. As an example, look at NonStop Enscribe files. There are 4 basic types, EDIT, key-sequenced, relative and unstructured. Creating, reading, writing and updating have unique requirements based on the underlying file’s type. It is possible (and recommended) that classes can be created to “wrap” or “encapsulate” what needs to be done for the each file type.
EDIT File derived from NonStop File
Attributes (same as NonStop File)
Create (overrides base class for unique handling)
Open (overrides base class for unique handling)
Read (overrides base class for unique handling)
As you can see, there are new terms and concepts to grasp for OOP. In future articles we will explore how these can be used. Feedback pleaseDo you find this tutorial blog helpful? Let us know what you think, and how we can make it even better. Don’t forget, you can subscribe to our blogs (top right-hand corner of this page) to get automatic email notification when a new blog is available.