Sunday, August 27, 2023

Decorator Design Pattern in Python

In object-oriented programming, the decorator pattern is a design pattern that allows behavior to be added to an individual object, dynamically, without affecting the behavior of other objects from the same class.

What problems can it solve?

- Responsibilities should be added to (and removed from) an object dynamically at run-time

- A flexible alternative to subclassing for extending functionality should be provided.

The UML diagram of the example is given below:



When using subclassing, different subclasses extend a class in different ways. But an extension is bound to the class at compile-time and can't be changed at run-time.

The decorator pattern can be used to extend (decorate) the functionality of a certain object statically, or in some cases at run-time, independently of other instances of the same class.

This is achieved by designing a new Decorator class that wraps the original class. This wrapping could be achieved by the following sequence of steps:

Subclass the original Component class into a Decorator class (see UML diagram);

- In the Decorator class (SpecialistTeacher), add a Component reference as an attribute;

- In the Decorator class, pass a Component to the Decorator constructor to initialize the Component attribute;

- In the Decorator class, forward all Component methods to the Component pointer; and

- In the ConcreteDecorator class (specialistMathTeacher, specialistChemistryTeacher, etc), override any Component method(s) whose behavior needs to be modified.

This pattern is designed so that multiple decorators can be stacked on top of each other, each time adding a new functionality to the overridden method(s).

Note that decorators and the original class object share a common set of features. In the UML diagram, the doWork() and calculateSalary() methods were available in both the decorated and undecorated versions.

Here is the source code of the Decorator Design Pattern in Python:

from abc import ABC, abstractmethod

class Teacher(ABC):
@abstractmethod
def calculateSalary(self):
pass
def doWork(self):
pass

class BasicTeacher(Teacher):
def __init__(self, baseSalaryForATeacher):
self.baseSalaryForTeacher = baseSalaryForATeacher

def calculateSalary(self):
return self.baseSalaryForTeacher
def doWork(self):
pass

##Decorator
class SpecialistTeacher(Teacher):
def __init__(self, teacher):
self.teacher = teacher

def calculateSalary(self):
self.specialistTeacherBaseSalary = self.teacher.calculateSalary()
return self.specialistTeacherBaseSalary
def doWork(self):
super().doWork()
self.teacher.doWork()

class SpecialistPhysicsTeacher(SpecialistTeacher):
def __init__(self, specialistTeacher):
super().__init__(specialistTeacher)

def calculateSalary(self):
return super().calculateSalary() + 8000

def doWork(self):
super().doWork()
print("\n I am a specialist Physics Teacher. I teach Physics")


class SpecialistMathsTeacher(SpecialistTeacher):
def __init__(self, specialistTeacher):
super().__init__(specialistTeacher)

def calculateSalary(self):
return super().calculateSalary() + 10000

def doWork(self):
super().doWork()
print("\n I am a specialist Maths Teacher. I teach Maths")


class SpecialistChemistryTeacher(SpecialistTeacher):
def __init__(self, specialistTeacher):
super().__init__(specialistTeacher)

def calculateSalary(self):
return super().calculateSalary() + 7000

def doWork(self):
super().doWork()
print("\n I am a specialist Chemistry Teacher. I teach Chemistry")

# Press the green button in the gutter to run the script.
if __name__ == '__main__':
specialistPhyTeacher = SpecialistPhysicsTeacher(SpecialistTeacher(BasicTeacher(10000)))

specialistPhyTeacher.doWork()

print("\n My Salary is ", specialistPhyTeacher.calculateSalary())

specialistphymathsTeacher = SpecialistMathsTeacher(SpecialistPhysicsTeacher
                                          (SpecialistTeacher(BasicTeacher(10000))))

specialistphymathsTeacher.doWork()

print("\n My Salary is ", specialistphymathsTeacher.calculateSalary())

If we run the above program, the output will look like the following:


I am a specialist Physics Teacher. I teach Physics


My Salary is  18000


 I am a specialist Physics Teacher. I teach Physics


 I am a specialist Maths Teacher. I teach Maths


 My Salary is  28000


Friday, August 25, 2023

The Template Method Design Pattern...

 It is a behavioral design pattern. It lets us define the skeleton of an algorithm, delegating some steps to the subclasses.

There are mainly two participants in this design pattern

- AbstractClass : It defines the abstract primitive methods that the subclasses will override. It also implements a template method which define the algorithm.

- ConcreteClass : it implements the abstract primitive methods of the Abstract Class.

Let us try to understand this design pattern from an example.

Suppose we are modeling the daily activity of an engineering student in college.

All students need to sign in and sign out in a common register. So these common tasks are part of the Base class.

However, each student has to attend the classes of his own stream - maybe Electronics, Computer Science, Mechanicals, etc.

So this part of the basic activity depends on the stream of the student and constitutes part of the Concrete class.

The UML diagram of the code is as follows:



Here is the source code of the Template Method Design Pattern

from abc import ABC, abstractmethod

class EngineeringStudent(ABC):
def __init__(self):
pass
def signIn(self):
print("\n Start of the day. I need to sign in the common register")
def signOut(self):
print("\n End of the day. I need to sign out in the common register")
@abstractmethod
def attendClass(self):
pass
def activityofAStudent(self):
self.signIn()
self.attendClass()
self.signOut()

class ElectronicsStudent(EngineeringStudent):

def __init__(self):
print("\n I am an Electronics Student")

def attendClass(self):
print("\n Attend the classes in the Electronics dept")

class ComputerScienceStudent(EngineeringStudent):
def __init__(self):
print("\n I am a CS Student")
def attendClass(self):
print("\n Attend the classes in the CS dept")


# Press the green button in the gutter to run the script.
if __name__ == '__main__':
electronicsStudent = ElectronicsStudent()
electronicsStudent.activityofAStudent()
csStudent = ComputerScienceStudent()
csStudent.activityofAStudent()

# See PyCharm help at https://www.jetbrains.com/help/pycharm/

If we run the above program, the output will be as follows:


 I am an Electronics Student


 Start of the day. I need to  sign in the common register


 Attend the classes in the Electronics dept


 End of the day. I need to sign out in the common register


 I am a CS Student


 Start of the day. I need to  sign in the common register


 Attend the classes in the CS dept


 End of the day. I need to sign out in the common register


Thursday, August 24, 2023

Memento Design Pattern in Python...

This design pattern lets you save the state of an object without revealing the implementation.

There are mainly three participants in this design pattern

- Memento: stores the internal state of the Originator object. How much state of the Originator the memento will store completely depends upon the Originator

- Originator: It creates a memento containing a snapshot of its current internal state. It also uses the Memento to restore the Original state

Caretaker: It's responsible for the memento's safekeeping.

The memento design pattern helps to implement Undo facilities for any application. Think about a word processor app - at any point in time we can undo and get back the earlier state of the document - here lies the greatness of the memento design pattern.

The UML class diagram of the Memento pattern looks like the following:




The source code for the Memento Design Pattern is as follows:

cclass Originator:
    _state = ""

def set(self, state):
print(f"Originator: Setting state to {state}")
self._state = state

def save_to_memento(self):
return self.Memento(self._state)

def restore_from_memento(self, m) :
self._state = m.get_saved_state()
print(f"Originator: State after restoring from Memento: {self._state}")

class Memento:

def __init__(self, state):
self._state = state

def get_saved_state(self):
return self._state

class Caretaker:
def __init__(self, originator):
self.originator = originator
self.saved_states = []

def saveState(self):
self.saved_states.append(self.originator.save_to_memento())

def undo(self):
if not len(self.saved_states):
return
self.originator.restore_from_memento(self.saved_states.pop())

# Press the green button in the gutter to run the script.
if __name__ == '__main__':
originator = Originator()
caretaker = Caretaker(originator)
originator.set("State1")
caretaker.saveState()
originator.set('State2')
caretaker.saveState()

originator.set("State3")
caretaker.saveState()

originator.set("State4")
caretaker.saveState()
print("\nClient: Now, let's rollback!\n")
caretaker.undo()
print("\nClient: Once more!\n")
caretaker.undo()

If we run the above lines of code, the output will be:


Originator: Setting state to State1
Originator: Setting state to State2
Originator: Setting state to State3
Originator: Setting state to State4

Client: Now, let's rollback!

Originator: State after restoring from Memento: State4

Client: Once more!

Originator: State after restoring from Memento: State3

Wednesday, August 23, 2023

Facade Design Pattern in Python...

This design pattern provides a simplified and unified interface to hide the inner complexities of several subsystems or libraries.

As most of the time, the user of a subsystem does not want to know about the internal complexities. He just wants a simplified interface to use the subsystem. Subsystems become complex as they evolve. A facade can provide this simplified interface to the users of the subsystem.

The main participants of the Facade design pattern are

- facade itself

- and the several subsystems

The subsystems have no knowledge about the facade - meaning they don't keep any reference to the facade.

Let me give you an example.

Suppose there are many geometrical shapes whose drawing functionalities are complex and each one must be drawn differently. But the client really does not want to go into that complexity.

Here comes the facade pattern in the rescue. This pattern will give a single method called drawShapes which will take care of all the internal complexity of the individual shapes.

The UML class diagram of the facade design pattern example looks like the following:


Here goes the source code of the example.

from abc import ABC, abstractmethod

class Shape(ABC):
@abstractmethod
def draw(self):
pass

class Circle(Shape):
def draw(self):
print("Special method to draw a circle")

class Rectangle(Shape):
def draw(self):
print("Special method to draw a rectangle")

class Triangle(Shape):
def draw(self):
print("Special method to draw a triangle")

class FacadeToShape:
def __init__(self, circle, rectangle, triangle):
self.circle = circle
self.rectangle = rectangle
self.triangle = triangle

def drawCircle(self):
self.circle.draw()
def drawRectangle(self):
self.rectangle.draw()
def drawTriangle(self):
self.triangle.draw()

def drawShapes(self):
self.drawCircle()
self.drawTriangle()
self.drawRectangle()


# Press the green button in the gutter to run the script.
if __name__ == '__main__':
facateToShape = FacadeToShape(Circle(), Rectangle(), Triangle())
facateToShape.drawShapes()

Tuesday, August 22, 2023

Builder Design Pattern implemented using Python...

 Today I am presenting the Builder Pattern in Python.

As the name suggests - it is part of the creational pattern.

The idea is that if a class has many member variables - and the final object may not depend on all of them - and the number of parameters that the constructor takes varies - instead of making a lot of overloaded constructors, we use this Builder pattern

The code footprint is heavily reduced - as there is no need to create a matching number of overloaded constructors to match each and every permutation and combination of the member variables passed in the constructors.

In the given example, we have created a common Student class which may represent a 10th std, a 12th std, or an engineering student - maybe in 1st yr or 2nd year, or third year or maybe in the final fourth year.

In the case of a student who is a qualified engineer, we need to supply all the marks…

But in the case of a 2nd-year student - we don’t need to bother about third-year marks or fourth-year marks, the 10th, 12th, and 1st-year marks are sufficient to represent the object of a second-year student vis-a-vis marks.

Here goes the code for the CS students of the UNIVERSE.

from abc import  ABC, abstractmethod

class Student:
class Builder:

def __init__(self):
self.name=""
self.address = ""
self.tenthmarks = 0
self.twelfthmarks = 0
self.firstyrmarks = 0
self.secondyrmarks = 0
self.thirdyrmarks = 0
self.fourthyrmarks = 0

def setname(self, name):
self.name = name
return self
def setaddress(self, address):
self.address = address
return self
def settenthmarks(self, tenthmarks):
self.tenthmarks = tenthmarks
return self
def settwelfthmarks(self, twelfthmarks):
self.twelfthmarks = twelfthmarks
return self
def setfirstyrmarks(self, firstyrmarks):
self.firstyrmarks = firstyrmarks
return self
def setsecondyrmarks(self, secondyrmarks):
self.secondyrmarks = secondyrmarks
return self
def setthirdyrmarks9(self, thirdyrmarks):
self.thirdyrmarks = thirdyrmarks
return self
def setfourthyrmarks(self, fourthyrmarks):
self.fourthyrmarks = fourthyrmarks
return self

def build(self):
return Student(self)

def __init__(self, builder):
self.name = builder.name
self.addrees = builder.address
self.tenthmarks = builder.tenthmarks
self.twelfthmarks = builder.twelfthmarks
self.firstyrmarks = builder.firstyrmarks
self.secondyrmarks = builder.secondyrmarks
self.thirdyrmarks = builder.thirdyrmarks
self.fourthyrmarks = builder.fourthyrmarks

def displayData(self):
if self.name != "":
print("Name : " , self.name)

if self.addrees != "":
print("Address : ", self.addrees)

if self.tenthmarks != 0:
print("10th Marks : ", self.tenthmarks)

if self.twelfthmarks != 0:
print("12th Marks : ", self.twelfthmarks)

if self.firstyrmarks != 0:
print("1st Yr Marks : ",self.firstyrmarks)

if self.secondyrmarks != 0:
print("2nd Yr Marks : ", self.secondyrmarks)

if self.thirdyrmarks != 0:
print ("3rd Yr marks : ", self.thirdyrmarks)

if self.fourthyrmarks != 0:
print ("4th Yr Marks : ", self.fourthyrmarks)


# Press the green button in the gutter to run the script.
if __name__ == '__main__':
ram12th = Student.Builder().setname("Ram").setaddress("Kolkata").
settenthmarks(50).build()

shyam2ndYr = Student.Builder().setname("Shyam").setaddress("Delhi")
.settenthmarks(70).settwelfthmarks(78).setfirstyrmarks(70).build()

ram12th.displayData()

shyam2ndYr.displayData()

If we run the above program, the output will be as follows:

Name :  Ram
Address :  Kolkata
10th Marks :  50

Name :  Shyam
Address :  Delhi
10th Marks :  70
12th Marks :  78
1st Yr Marks :  70

As it is clear for Ram, till 10th marks was important whereas, for Shyam, on the other hand, marks till 1st year are important.

Sunday, August 20, 2023

Visitor Pattern in Python...

 Visitor design pattern allows the addition of completely different functionalities to an existing class without much alteration in the original class.

Let me explain it with an example.

Suppose there are two items a shop sells - Book and Medicine

Now say, normally these two Item classes would look like two - what we call in Java as POJO classes where the most important attribute will be the price.

So far so good.

Now suppose the government is running 

- one literacy mission

and 

- one Health mission

Under these missions, few books are given huge discounts, and few medicines are sold at discounted prices.

Without the Visitor pattern, the algorithm of the discounts would have been put inside the POJO classes which might create maintenance problems in the future when the algorithm for discount changes.

With the visitor pattern, we encapsulate all these discount algorithms inside a special method called visit which comes from a Visitor interface.

So if it is a LiteracyMissionVisitor, the special algorithm offers a discount on special books whereas if it is a HealthMissionVisitor, the discount goes to specific medicines – all we have to do is to call accept on these special Book and Medicine objects passing the proper Visitor object,

That's it...

The UML class diagram looks as follows:




And here goes the source code of this Visitor Pattern

from abc import ABC, abstractmethod

class Visitor(ABC):
@abstractmethod
def visit(self, book):
pass
@abstractmethod
def visit(self, medicine):
pass

class Visitable(ABC):
@abstractmethod
def accept(self, visitor):
pass

class Book(Visitable):
def __init__(self, price):
self.price = price
def accept(self, visitor):
return visitor.visit(self)

def getPrice(self):
return self.price

class Medicine(Visitable):
def __init__(self, price):
self.price = price

def accept(self, visitor):
return visitor.visit(self)

def getPrice(self):
return self.price

class LiteracyMissionVisitor(Visitor):
def __init__(self, percentagediscountOnBook):
self.discount = percentagediscountOnBook
def visit(self, book):
book.price = book.price - (book.price * self.discount)/100
return book.price

class HealthMissionVisitor(Visitor):
def __init__(self, percentagediscountOnMedicine):
self.discount = percentagediscountOnMedicine

def visit(self, medicine):
medicine.price = medicine.price - (medicine.price * self.discount)/100
return medicine.price




# Press the green button in the gutter to run the script.
if __name__ == '__main__':

literacyMissionVisitor = LiteracyMissionVisitor(50)

chandaMama = Book(100)

print("Original price of the book is ", chandaMama.getPrice())

print("Due to literacy mission, there is huge discount on the book.
        After discount, the price is ", chandaMama.accept(literacyMissionVisitor))

healthDriveVisitor = HealthMissionVisitor(70)

vitaminDCapsule = Medicine(200)

print("Original price of the medinine is ", vitaminDCapsule.getPrice())

print("Due to health mission the reduced price of the
            medicine is ", vitaminDCapsule.accept(healthDriveVisitor))


If we run this program, the output will be as follows:

Original price of the book is  100

Due to literacy mission, there is huge discount on the book. After discount, the price is  50.0

Original price of the medinine is  200

Due to health  mission the reduced price of the medicine is  60.0




Saturday, August 19, 2023

Mediator Design Pattern in Python...

This design pattern lets you reduce chaotic dependencies between objects. The pattern restricts direct communications between the objects and forces them to collaborate only via a mediator object.

The Mediator interface declares a method used by components to notify the mediator about various events. The Mediator may react to these events and triggers specific components to execute different yet specific tasks.

The Base Component provides the basic functionality of storing a mediator's reference inside the component.

Concrete Components implement various functionality. They don't depend on other components.

Let me explain it to you with an example.

Suppose two students Ridit and Rajdeep take a lot of responsibility in a class. But something bad happens between them, and hence they don't talk to each other. So, here comes the ClassMonitor - as a Mediator between Rajdeep and Ridit - if Ridit does anything that needs Rajdeep to do another task, Ridit notifies the Class Monitor, and then the Class Monitor asks Rajdeep to execute the necessary task.

Here's the class diagram of the Mediator Pattern

There are many uses for this design pattern. This design pattern can be found in most of the widget message-passing systems - individual widgets don't pass or communicate with each other - but they communicate through the container window.

For Android engineers - you remember how two fragments talk to each other through the container window.

Here goes the source code for this Design Pattern.

Enjoy.

Happy learning.

from abc import ABC, abstractmethod

class ClassMonitor(ABC):
@abstractmethod
def notify(self, sender, event):
pass
class ConcreteClassMonitor(ClassMonitor):
def __init__(self, student1, student2):
self.student1 = student1
self.student2 = student2

def notify(self, sender, event):
if event == "A":
print("The class Monitor reacts to event A and triggers Rajdeep to do task C")
self.student2.do_c()
elif event == "D":
print("The class Monitor reacts to event D and triggers Ridit to do Task B and Rajdeep to do Task C")
self.student1.do_b()
self.student2.do_c()

class BaseStudent:
def __init__(self, monitor):
self._monitor = monitor

def getMonitorr(self):
return self._monitor
def setMonitor(self, monitor):
self._monitor = monitor

class Ridit(BaseStudent):
def do_a(self):
print("Ridit does A.")
self._monitor.notify(self, "A")

def do_b(self):
print("Ridit does B.")
self._monitor.notify(self, "B")

class Rajdeep(BaseStudent):
def do_c(self):
print("Rajdeep does C.")
self._monitor.notify(self, "C")

def do_d(self):
print("Rajdeep does D")
self._monitor.notify(self, "D")

if __name__ == '__main__':
ridit = Ridit(None)
rajdeep = Rajdeep(None)
classMonitor = ConcreteClassMonitor(ridit,rajdeep)
ridit.setMonitor(classMonitor)
rajdeep.setMonitor(classMonitor)

print("Ma'am asks Ridit to do A")
ridit.do_a()

print("Ma'am asks Rajdeep to do D.")
rajdeep.do_d()
If we run the above program the output will be like the following:


Ma'am asks Ridit to do A
Ridit does A.
The class Monitor reacts to event A and triggers Rajdeep to do task C
Rajdeep does C.
Ma'am asks Rajdeep to do  D.
Rajdeep does D
The class Monitor reacts to event D and triggers Ridit to do Task B and Rajdeep to do Task C
Ridit does B.
Rajdeep does C.


Friday, August 18, 2023

Composite Design Pattern in Python....

 When I first started studying the Gang of Four book back in 2003-2004, it was an absolutely new thing to me. I must admit today that not everything became clear at that time. But gradually, the knowledge is being imbibed, and now while teaching my young son Ridit on this subject, I just love it.

Moreover, as I am now comfortable with three languages namely C++, Java, and Python, recreating the stuff for various languages looks pretty easy now.

So, today, I am rewriting the Composite Design Pattern in Python. Here goes my original Composite Design pattern implemented using C++ and written in 2008.





And here goes the exploration of the Composite Design Pattern by my young son, Ridit, currently a class VII student.



And here goes the Composite Design Pattern implemented in Python.

I hope you will like it.

from abc import ABC, abstractmethod

class Shape(ABC):

def __init__(self):
self.parent = None
@abstractmethod
def add(self, shape):
pass

@abstractmethod
def remove(self, shape):
pass

def getparent(self):
return self.parent

def setparent(self, parent):
self.parent = parent

@abstractmethod
def display(self):
pass


class CompositeShape(Shape):
def __init__(self):
self.listofShapes = []

def add(self, shape):
shape.setparent(self)
self.listofShapes.append(shape)


def remove(self, shape):
self.listofShapes.remove(shape)
shape.setparent(None)

def setParent(self, parent):
self.parent = parent

def display(self):
pass


class Point(Shape):
def __init__(self, x, y):
self.x = x
self.y = y

def display(self):
print ("X = ", self.x, "Y = ", self.y)

def add(self, shape):
print("This is a leaf class.... Can't add to it...")

def remove(self, shape):
print("This is a leaf class.... Can't remove from it...")

class Line(CompositeShape):
def __init__(self, p1, p2):
super().__init__()
self.add(p1)
self.add(p2)

def display(self):
print("The starting and end points of the line are")
for shape in self.listofShapes:
shape.display()

class Quadrilateral(CompositeShape):
def __init__(self, p1,p2,p3,p4):
super().__init__()
self.add(p1)
self.add(p2)
self.add(p3)
self.add(p4)

def display(self):
print("The four corners of the quadrilateral are ")
for shape in self.listofShapes:
shape.display()


# Press the green button in the gutter to run the script.
if __name__ == '__main__':
p1 = Point(10,20)
p2 = Point(30,40)
p3 = Point(50,60)
p4 = Point(70,80)

p1.add(p2)

L1 = Line(p1,p2)
q1 = Quadrilateral(p1,p2,p3,p4)

p1.display()
p2.display()
L1.display()

q1.display()

If we execute the above code, the console window will display the following result


This is a leaf class... Can't add to it...
X =  10 Y =  20
X =  30 Y =  40
The starting and end points of the line are
X =  10 Y =  20
X =  30 Y =  40
The four corners of the quadrilateral are 
X =  10 Y =  20
X =  30 Y =  40
X =  50 Y =  60
X =  70 Y =  80

Wednesday, August 16, 2023

Chain Of Responsibility in Python...

 In this design pattern, there are some sorts of executors of a command tied in a chain - at different levels. Depending upon the complexity of the task, the command is handled at different levels. Each receiver is well aware of if he can handle the command. If he can't he simply passes the buck to the next person in the chain. Once the command reaches the highest level of the chain, it must be handled there as there is no more successor after the highest authority.

The idea is that the command is always delivered at the lowest level of the chain and then it moves forward - one step at a time till it is handled at one such level.

Here is the class diagram of the Chain of Responsibility design pattern.


Here goes the source code of the chain of responsibility implemented in Python...

from abc import ABC, abstractmethod


class ICommand(ABC):
def __init__(self, level):
self.level = level


class CommandReceiver(ABC):
def __init__(self, successor):
self.successor = successor


@abstractmethod
def handleCommandImpl(self, command):
pass

def handleCommand(self, command):
retType = self.handleCommandImpl(command)
if self.successor != None and retType == False:
self.successor.handleCommand(command)
else:
return



class ReceiverLevel1(CommandReceiver):
def __init__(self, successor):
self.successor = successor

def handleCommandImpl(self, command):
if command.level == 1:
print("The Command is handled at level 1")
return True
else:
print("Forwarding the command from level 1 to level 2")
return False


class ReceiverLevel2(CommandReceiver):
def __init__(self, successor):
self.successor = successor

def handleCommandImpl(self, command):
if command.level == 2:
print("The Command is handled at level 2")
return True
else:
print("Forwarding the command from level 2 to level 3")
return False


class ReceiverLevel3(CommandReceiver):
def __init__(self, successor):
self.successor = successor

def handleCommandImpl(self, command):
if command.level == 3:
print("The Command is handled at level 3")
return True
else:
print("Last level... The Command has to be managed here...")
return False


# Press the green button in the gutter to run the script.
if __name__ == '__main__':
commandLevel1 = ICommand(1)
commandLevel2 = ICommand(2)
commandLevel3 = ICommand(3)

receiverLevel3 = ReceiverLevel3(None)
receiverLevel2 = ReceiverLevel2(receiverLevel3)
receiverLevel1 = ReceiverLevel1(receiverLevel2)

receiverLevel1.handleCommand(commandLevel3)