Τρίτη 14 Ιουλίου 2020

Null Object Pattern (OOP)

In module Client we send three objects of type Abstract, at least. So we send a NullObject, a Concrete and a ConcreteOther. 

Any method and member after a Class: label in a Class used only at construction, they didn't included in the final object.
So from class Logger the constructor Logger not included in the Client side. The same hold for Concrete constructor and ConcreteOther constructor. A module pass the stack of values to the module which call, so we pass 1001 to function Concrete() which call the module Concrete without popping the value, but calling the logger constructor we get the value in private this.myid (we use .myid as this.myid).


\\ Null Object Pattern
Class Abstract {
      Module dosomething {
            error "Abstract"
      }
}
Class NullObject as Abstract {
      Module final dosomething {
            \\ do nothing
      }
}
Class Logger {
Private:
      myid=0
Class:
      Module Logger (.myid) {
      }
}
Class Concrete as Logger as Abstract {
      Module final dosomething {
            Print "Log to file from ";.myid
      }
Class:
      Module Concrete {
            .Logger
      }
}
Class ConcreteOther as Logger as Abstract {
      Module final dosomething {
            Print "Log to Screen from ";.myid
      }
Class:
      Module ConcreteOther {
            .Logger
      }
}
Module Client(a as Abstract, b as Abstract, c as Abstract) {
      Dim a(3)
      a(0)=a
      a(1):=b, c
      For i=0 to 2
            For a(i) {
                  .dosomething
            }
      Next
}
Client NullObject(), Concrete(1001), ConcreteOther(2002)


Δεν υπάρχουν σχόλια:

Δημοσίευση σχολίου

You can feel free to write any suggestion, or idea on the subject.