How to resolve the algorithm Classes step by step in the COBOL programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Classes step by step in the COBOL programming language

Table of Contents

Problem Statement

In object-oriented programming class is a set (a transitive closure) of types bound by the relation of inheritance. It is said that all types derived from some base type T and the type T itself form a class T. The first type T from the class T sometimes is called the root type of the class. A class of types itself, as a type, has the values and operations of its own. The operations of are usually called methods of the root type. Both operations and values are called polymorphic. A polymorphic operation (method) selects an implementation depending on the actual specific type of the polymorphic argument. The action of choice the type-specific implementation of a polymorphic operation is called dispatch. Correspondingly, polymorphic operations are often called dispatching or virtual. Operations with multiple arguments and/or the results of the class are called multi-methods. A further generalization of is the operation with arguments and/or results from different classes.

A polymorphic value has a type tag indicating its specific type from the class and the corresponding specific value of that type. This type is sometimes called the most specific type of a [polymorphic] value. The type tag of the value is used in order to resolve the dispatch. The set of polymorphic values of a class is a transitive closure of the sets of values of all types from that class. In many OO languages the type of the class of T and T itself are considered equivalent. In some languages they are distinct (like in Ada). When class T and T are equivalent, there is no way to distinguish polymorphic and specific values.

Create a basic class with a method, a constructor, an instance variable and how to instantiate it.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Classes step by step in the COBOL programming language

Source code in the cobol programming language

       IDENTIFICATION DIVISION.
       CLASS-ID. my-class INHERITS base.
       
       *> The 'INHERITS base' and the following ENVIRONMENT DIVISION
       *> are optional (in Visual COBOL).
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       REPOSITORY.
           CLASS base.
     
           *> There is no way (as far as I can tell) of creating a
           *> constructor. However, you could wrap it with another
           *> method to achieve the desired effect.
           *>...
     
           OBJECT.
               *> Instance data
               DATA DIVISION.
               WORKING-STORAGE SECTION.
               01  instance-variable PIC 9(8).
       
               *> Properties can have getters and setters automatically
               *> generated.
               01  a-property        PIC 9(8) PROPERTY.
               
               PROCEDURE DIVISION.
       
               METHOD-ID. some-method.
               PROCEDURE DIVISION.
                   *> ...
               END METHOD some-method.
           END OBJECT.
       END CLASS my-class.
       
       IDENTIFICATION DIVISION.
       PROGRAM-ID. example-class-use.
       
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       REPOSITORY.
           *> These declarations brings the class and property into
           *> scope.
           CLASS my-class
           PROPERTY a-property. 
                  
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       *> Declaring a my-class reference variable.
       01  instance USAGE OBJECT REFERENCE my-class.
       
       PROCEDURE DIVISION.
       
           *> Invoking a static method or (in this case) a constructor.
           INVOKE my-class "new" RETURNING instance
           
           *> Invoking an instance method.
           INVOKE instance "some-method"

           *> Using the setter and getter of a-property.
           MOVE 5 TO a-property OF instance
           DISPLAY a-property OF instance
       
           GOBACK
           .
           
       END PROGRAM example-class-use.


  

You may also check:How to resolve the algorithm Run-length encoding step by step in the V (Vlang) programming language
You may also check:How to resolve the algorithm Soundex step by step in the Picat programming language
You may also check:How to resolve the algorithm Lychrel numbers step by step in the Swift programming language
You may also check:How to resolve the algorithm Regular expressions step by step in the SNOBOL4 programming language
You may also check:How to resolve the algorithm Sorting algorithms/Sleep sort step by step in the Icon and Unicon programming language