• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Guru: Procedure Driven RPG And Adopting The Pillars Of Object-Oriented Programming

    February 19, 2024 Gregory Simmons

    The four pillars of object-oriented programming (OOP): abstraction, encapsulation, inheritance, and polymorphism, were not created at a single point in time. They evolved gradually over several years, with contributions from various researchers and programmers. Here’s a brief overview of their evolution:

    1. Abstraction:

    • Alan Kay is credited with introducing the concept of abstraction in the 1960s with his work on Simula.
    • Abstraction gained further traction with the development of Smalltalk in the 1970s.
    1. Encapsulation:

    • David Parnas, in his 1972 paper “On the Criteria To Be Used in Decomposing Systems into Modules,” laid the groundwork for encapsulation by emphasizing the importance of information hiding and data protection.
    • Encapsulation became a core principle of OOP with the development of languages like C++ and Java in the 1980s and 1990s.
    1. Inheritance:

    • The concept of inheritance has its roots in Simula as well.
    • It became widely used in object-oriented languages like C++ and Java, allowing developers to create new classes based on existing ones.
    1. Polymorphism:

    • Polymorphism emerged in the 1970s with languages like Lisp and Smalltalk.
    • It became a key feature of OOP languages like C++ and Java, enabling different objects to respond to the same message in different ways.

    Importance of OOP in Program Development

    OOP offers several advantages over traditional procedural programming paradigms:

    • Increased modularity: OOP allows developers to break down code into smaller, self-contained units called objects, making it easier to understand, maintain, and reuse code.
    • Improved code reusability: By inheriting from existing classes, developers can reuse code and avoid writing redundant logic.
    • Encapsulation: Encapsulation protects data from unauthorized access and modification, leading to more robust and secure programs.
    • Enhanced maintainability: OOP code is typically easier to maintain and modify due to its modularity and encapsulation.
    • Flexibility and extensibility: OOP programs are more flexible and extensible due to their ability to inherit and adapt existing code.

    While RPGLE doesn’t fully embrace all tenets of object-oriented programming, it does support two of the four pillars:

    Encapsulation

    Encapsulation involves bundling data and the code that operates on that data within a single unit, protecting the data from external modification and promoting modularity. This is how RPGLE implements encapsulation:

    • Procedures: RPGLE procedures effectively encapsulate code and data, acting as self-contained units that can be reused and managed independently.
    • Prototypes: Prototypes act as blueprints for procedures, defining their structure and accessibility, further enforcing encapsulation.

    Inheritance

    Inheritance allows new classes (or data types in RPGLE) to inherit properties and methods from existing ones, fostering code reusability and hierarchical relationships. This is how RPGLE implements inheritance:

    • Data types: RPGLE supports inheritance through sub-data types, enabling new data types to inherit characteristics (fields and subfields) from base types.

    Below is an example of inheritance:

    1	**FREE
    2	Ctl-Opt Main(demonstrate_inheritance);
    
    3	dcl-ds Parent Qualified Template;
    4	  Name char(30);
    5	  Age int(10);
    6	end-ds;
    
    7	dcl-ds Child Qualified;
    8	  base_Info likeds(Parent);
    9	  Grade Char(2);
    10	end-ds;
    
    11	dcl-proc demonstrate_inheritance;
    
    12	  dcl-ds ParentObj likeds(Parent);
    13	  dcl-ds ChildObj  likeds(Child);
    
    14	  ParentObj.Name = 'John Doe';
    15	  ParentObj.Age = 40;
    
    16	  ChildObj.base_Info.Name = 'Jane Smith';
    17	  ChildObj.base_Info.Age = 10;
    18	  ChildObj.Grade = 'A';
    
    19	  dsply ('Parent Name: ' + ParentObj.Name);
    20	  dsply ('Parent Age: '  + %char(ParentObj.Age));
    
    21	  dsply ('Child Name: '  + ChildObj.base_Info.Name);
    22	  dsply ('Child Age: '   + %Char(ChildObj.base_Info.Age));
    23	  dsply ('Child Grade: ' + ChildObj.Grade);
    
    24	end-proc demonstrate_inheritance;
    

    In the above example, starting at line 3 I have a simple data structure ‘Parent’ with Name and Age subfields. At line 7 I have a ‘Child’ data structure, which will have the same subfields as ‘Parent,’ but also has a ‘Grade’ subfield. In this fashion, we can say that the ‘Child’ data structure inherits its first two subfields from the ‘Parent’ data structure. As I always tell my students, ‘…but don’t take my word for it, code this up yourself and inspect it closer in debug.’

    In summary, while RPGLE doesn’t offer a complete object-oriented programming experience, its support for encapsulation and inheritance enables developers to achieve some benefits of OOP, such as code reusability, modularity, and organization.

    Until next time, happy coding.

    Gregory Simmons is a software engineer with PC Richard & Son. He started on the IBM i platform in 1994, graduated with a degree in Computer Information Systems in 1997 and has been working on the OS/400 and IBM i platform ever since. He has been a registered instructor with the IBM Academic Initiative since 2007, and holds a COMMON Application Developer certification. When he’s not trying to figure out how to speed up legacy programs, he enjoys speaking at COMMON and other technical conferences, running, backpacking, SCUBA diving, hunting, and fishing.

    RELATED STORIES

    Guru: Getting Started With The Code 4 i Extension Within VS Code

    Guru: Procedure Driven RPG Means Keeping Your Variables Local

    Guru: Procedure Driven RPG With Linear-Main Programs

    Guru: Speeding Up RPG By Reducing I/O Operations, Part 2

    Guru: Speeding Up RPG By Reducing I/O Operations, Part 1

    Guru: Watch Out For This Pitfall When Working With Integer Columns

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags: Tags: C, Java, Lisp, object- oriented programming, OOP, RPGLE, Smalltalk

    Sponsored by
    WorksRight Software

    Do you need area code information?
    Do you need ZIP Code information?
    Do you need ZIP+4 information?
    Do you need city name information?
    Do you need county information?
    Do you need a nearest dealer locator system?

    We can HELP! We have affordable AS/400 software and data to do all of the above. Whether you need a simple city name retrieval system or a sophisticated CASS postal coding system, we have it for you!

    The ZIP/CITY system is based on 5-digit ZIP Codes. You can retrieve city names, state names, county names, area codes, time zones, latitude, longitude, and more just by knowing the ZIP Code. We supply information on all the latest area code changes. A nearest dealer locator function is also included. ZIP/CITY includes software, data, monthly updates, and unlimited support. The cost is $495 per year.

    PER/ZIP4 is a sophisticated CASS certified postal coding system for assigning ZIP Codes, ZIP+4, carrier route, and delivery point codes. PER/ZIP4 also provides county names and FIPS codes. PER/ZIP4 can be used interactively, in batch, and with callable programs. PER/ZIP4 includes software, data, monthly updates, and unlimited support. The cost is $3,900 for the first year, and $1,950 for renewal.

    Just call us and we’ll arrange for 30 days FREE use of either ZIP/CITY or PER/ZIP4.

    WorksRight Software, Inc.
    Phone: 601-856-8337
    Fax: 601-856-9432
    Email: software@worksright.com
    Website: www.worksright.com

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    IBM: A Brand Is Not Everything, But It Is Important To Have A Good One IBM i In The Cloud: A Beginner’s Guide to Taking Your First Step

    3 thoughts on “Guru: Procedure Driven RPG And Adopting The Pillars Of Object-Oriented Programming”

    • Mihael says:
      February 19, 2024 at 7:11 am

      An example where inheritance (data and procedures) is used in RPG can be found in the OSSILE git repository on github: https://github.com/OSSILE/OSSILE/tree/master/code_examples/rpg/interfaces

      Reply
    • Matt Qualls says:
      February 20, 2024 at 8:36 am

      All too often, the check to determine if a procedure or subroutine is to be performed is done outside of that object. Encapsulating that check at the beginning of that object puts that rule inside the object where it should belong.

      Reply
    • John Blue says:
      February 24, 2024 at 8:16 pm

      Re: “Alan Kay is credited with introducing the concept of abstraction in the 1960s with his work on Simula.”

      Alan did work with Sinula but the concept of abstraction is credited to Barbara Liskov, https://en.wikipedia.org/wiki/Barbara_Liskov?wprov=sfti1#

      Reply

    Leave a Reply Cancel reply

TFH Volume: 34 Issue: 10

This Issue Sponsored By

  • Maxava
  • Meridian IT
  • Briteskies
  • Kisco Systems
  • WorksRight Software

Table of Contents

  • Lots Of Unanswered Questions On IBM i Subscriptions
  • IBM i In The Cloud: A Beginner’s Guide to Taking Your First Step
  • Guru: Procedure Driven RPG And Adopting The Pillars Of Object-Oriented Programming
  • IBM: A Brand Is Not Everything, But It Is Important To Have A Good One
  • IBM i PTF Guide, Volume 26, Number 7

Content archive

  • The Four Hundred
  • Four Hundred Stuff
  • Four Hundred Guru

Recent Posts

  • Big Blue Raises IBM i License Transfer Fees, Other Prices
  • Keep The IBM i Youth Movement Going With More Training, Better Tools
  • Remain Begins Migrating DevOps Tools To VS Code
  • IBM Readies LTO-10 Tape Drives And Libraries
  • IBM i PTF Guide, Volume 27, Number 23
  • SEU’s Fate, An IBM i V8, And The Odds Of A Power13
  • Tandberg Bankruptcy Leaves A Hole In IBM Power Storage
  • RPG Code Generation And The Agentic Future Of IBM i
  • A Bunch Of IBM i-Power Systems Things To Be Aware Of
  • IBM i PTF Guide, Volume 27, Numbers 21 And 22

Subscribe

To get news from IT Jungle sent to your inbox every week, subscribe to our newsletter.

Pages

  • About Us
  • Contact
  • Contributors
  • Four Hundred Monitor
  • IBM i PTF Guide
  • Media Kit
  • Subscribe

Search

Copyright © 2025 IT Jungle