• Phil Ly

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.

  1. 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.

  2. Why use OOP?

  3. Emphasis on data rather than procedure

  4. Programs are divided into Objects

  5. Data is protected and cannot normally be accessed by external functions

  6. Objects can communicate with each other through functions

  7. New data and functions can be easily added whenever necessary

  8. Follows bottom-up approach

  9. 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.

  10. 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.

  11. 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.

  1. 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.

  1. A base object – Telephone

  2. Attributes

  3. Phone number

  4. Dial type

  5. Service Provider

  6. Operation

  7. Make Call

  8. Answer Call

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.

  1. Cell Phone derived from Telephone

  2. Attributes (in addition to Telephone’s)

  3. Text  messages

  4. Pictures

  5. Operations (in addition to Telephone’s)

  6. Messaging

  7. Camera

  1. Smart Phone derived from Cell Phone

  2. Attributes (in addition to Cell Phone’s)

  3. Applications

  4. Operations (in addition to Cell Phone’s)

  5. Email

  6. Web Browsing

  7. 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.

  8. NonStop File

  9. Attributes

  10. File name

  11. File Type

  12. Operations

  13. Create

  14. Open

  15. Read

  16. EDIT File derived from NonStop File

  17. Attributes (same as NonStop File)

  18. Operations

  19. Create  (overrides base class for unique handling)

  20. Open (overrides base class for unique handling)

  21. 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.

 

#HPENonStop #NonStop #TICSoftware

1 view0 comments

Recent Posts

See All