How to resolve the algorithm Inheritance/Single step by step in the NetRexx programming language
How to resolve the algorithm Inheritance/Single step by step in the NetRexx programming language
Table of Contents
Problem Statement
Inheritance is an operation of type algebra that creates a new type from one or several parent types. The obtained type is called derived type. It inherits some of the properties of its parent types. Usually inherited properties are:
The class of the new type is a subclass of the classes rooted in the parent types. When all (in certain sense) properties of the parents are preserved by the derived type, it is said to be a Liskov subtype. When properties are preserved then the derived type is substitutable for its parents in all contexts. Usually full substitutability is achievable only in some contexts.
Inheritance is
Some single inheritance languages usually allow multiple inheritance for certain abstract types, interfaces in particular. Inheritance can be considered as a relation parent-child. Parent types are sometimes called supertype, the derived ones are subtype. This relation is transitive and reflexive. Types bound by the relation form a wp:Directed_acyclic_graph directed acyclic graph (ignoring reflexivity). With single inheritance it becomes a tree.
Show a tree of types which inherit from each other.
The tree should look like this:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Inheritance/Single step by step in the NetRexx programming language
Source code in the netrexx programming language
/* NetRexx */
options replace format comments java crossref symbols binary
class RInheritSingle public
method main(args = String[]) public static
animals = [ -
RInheritSingle_Animal(), -
RInheritSingle_Cat(), -
RInheritSingle_Dog(), -
RInheritSingle_Lab(), -
RInheritSingle_Collie() -
]
say 'Object ID'.left(12) 'Class type'.left(24) 'Superclass type'
say '.'.left(12, '.') '.'.left(24, '.') '.'.left(24, '.')
loop animal over animals
parse animal.whatAmI() oid ct st
say oid.left(12) ct.left(24) st
end animal
return
class RInheritSingle_Animal private
properties indirect
whatThatIs = String
whatThisIs = String
method RInheritSingle_Animal() public
-- Animal specific set-up
setWhatThatIs(this.getClass().getSuperclass().getSimpleName())
setWhatThisIs(this.getClass().getSimpleName())
return
method hashToString() public
return '@'(Rexx this.hashCode()).d2x().right(8, 0)
method whatAmI() public
iAmText = hashToString() getWhatThisIs() getWhatThatIs()
return iAmText
class RInheritSingle_Cat private extends RInheritSingle_Animal
method RInheritSingle_Cat() public
-- Do Cat specific set-up
return
class RInheritSingle_Dog private extends RInheritSingle_Animal
method RInheritSingle_Dog() public
-- Do Dog specific set-up
return
class RInheritSingle_Lab private extends RInheritSingle_Dog
method RInheritSingle_Lab() public
-- Do Lab specific set-up
return
class RInheritSingle_Collie private extends RInheritSingle_Dog
method RInheritSingle_Collie() public
-- Do Collie specific set-up
return
You may also check:How to resolve the algorithm Numbers which are the cube roots of the product of their proper divisors step by step in the Ruby programming language
You may also check:How to resolve the algorithm Quaternion type step by step in the XPL0 programming language
You may also check:How to resolve the algorithm Program termination step by step in the Pop11 programming language
You may also check:How to resolve the algorithm GUI enabling/disabling of controls step by step in the Perl programming language
You may also check:How to resolve the algorithm Generate Chess960 starting position step by step in the Elixir programming language