How to resolve the algorithm Inheritance/Single step by step in the EMal programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Inheritance/Single step by step in the EMal 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 EMal programming language

Source code in the emal programming language

in Org:RosettaCode
type Animal
model do end
type Dog extends Animal
model do end
type Cat extends Animal
model do end
type Lab extends Dog
model do end
type Collie extends Dog
model do end
type Main
var fuffy = Collie()
for each generic kind in generic[Animal, Dog, Cat, Lab, Collie]
  writeLine("Fuffy " + when(Generic.check(kind, fuffy), "is", "is not") + " a " + Generic.name(kind))
end

  

You may also check:How to resolve the algorithm Read entire file step by step in the REBOL programming language
You may also check:How to resolve the algorithm Boolean values step by step in the Picat programming language
You may also check:How to resolve the algorithm Non-continuous subsequences step by step in the Common Lisp programming language
You may also check:How to resolve the algorithm Leap year step by step in the MATLAB / Octave programming language
You may also check:How to resolve the algorithm Numerical integration/Gauss-Legendre Quadrature step by step in the Tcl programming language