Πέμπτη, 16 Ιουλίου 2020

Facade Pattern (OOP)

Facade Pattern use classes from libraries and place them as inner objects (groups in M2000), and provide a simplify interface (here a doSomething method). Inside this method we can call some of the inner objects public members.


\\ Facade Pattern
Function Package1 {
      Class Class1 {
            module operationA {
                  Print "Class1 operationA"
            }
      }
      Class Class2 {
      Private:
            x=10
      Public:
            module operationB {
                  Print "Class2 operationB", .x
            }
      Class:
            module Class2(.x) {
            }
      }
      Class Class3 {
            Group Inner1 {
            Private:
                  z=2000
            Public:
                  x=100
                  module operationD {
                        Print "Class3 inner1 operationD", .z, .x
                  }
            }
            module operationC {
                  \\ we can't read the .inner1.z because .z is private to .Inner1
                  Print "Class3 operationC", .inner1.x, valid(.inner1.z)=false
            }      
      }
      Class Facade {
      Private:
            \\ these are private inner clases
            \\ not pointer to objects.
            Class1 a
            Class2 b(300)
            Class3 c
      Public:
            module doSomething {
                  .a.OperationA
                  .b.OperationB
                  .c.OperationC
                  .c.inner1.OperationD
            }
      }
      =Facade()
}
M=Package1()
Print M is type Facade
M.doSomething

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

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