0% found this document useful (0 votes)
63 views5 pages

CSharp OOP Advanced Communication and Events Lab

Uploaded by

Baron Samedi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views5 pages

CSharp OOP Advanced Communication and Events Lab

Uploaded by

Baron Samedi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Lab: Object Communication and Events

This document defines the exercises for C# OOP Advanced" course @ Software University.
You can check your solutions here: Judge .

Part I: Chain of Responsibility, Command Design Pattern


1. Resources
NOTE: You need a public StartUp class with the namespace Heroes.
You are given a file with some classes. Place them in a new project and get familiar with them.

2. Logger - Chain of Responsibility


Create a Chain of Responsibility Logger and provide:
 enum LogType
o values - ATTACK, MAGIC, TARGET, ERROR, EVENT

 interface IHandler
o void Handle(LogType, String)
o void SetSuccessor(Handler)

 Concrete loggers that log messages to console:


o CombatLogger
o EventLogger

Log messages in format ("TYPE: message")

Solution
Create enum LogType

Create IHandler interface

© Software University Foundation. This work is licensed under the CC-BY-NC-SA license.

Follow us: Page 1 of 5


You can create an abstract logger, so you can abstract some of the functionalities

Create a concrete logger that extends Logger

Test the logger through you client.(In the Main method)

© Software University Foundation. This work is licensed under the CC-BY-NC-SA license.

Follow us: Page 2 of 5


Don't forget to inject the logger into any model that needs to log/print messages

3. Command
Create a Command Pattern Executor and provide:
 interface ICommand
o void Execute()

 interface IExecutor
o void ExecuteCommand(Command command)

 Concrete Executor named CommandExecutor implements IExecutor

 Concrete Commands
o TargetCommand with constructor (Attacker, Target)
o AttackCommand with constructor (Attacker)

Hints
Create the interfaces
Each new command should implement ICommand, so it can be executed by the IExecutor

Create as many commands as you like


Test your commands

Part II: Mediator, Observer Design Pattern


4. Mediator
Implement a Mediator Pattern groups and provide:
 interface IAttackGroup
o void AddMember(Attacker)

© Software University Foundation. This work is licensed under the CC-BY-NC-SA license.

Follow us: Page 3 of 5


o void GroupTarget(Target)
o void GroupAttack()

 Concrete class Group that implements IAttackGroup


 Concrete Commands:
o GroupTargetCommand with constructor (IAttackGroup, ITarget)
o GroupAttackCommand with constructor (IAttackGroup)

Hints
Implement Group implements IAttackGroup - this will be the concrete mediator

x
Create some group commands, following the logic from the previous problem
Test the mediator

© Software University Foundation. This work is licensed under the CC-BY-NC-SA license.

Follow us: Page 4 of 5


5. Observer
Implement the Observer Design Pattern by providing the following:
 interface ISubject
o void Register(Observer)
o void Unregister(Observer)
o void NotifyObservers()

 interface IObserver
o Update(int)
If a Target dies, it should send reward to all of its Observers

Hints
Create the interfaces
IAttacker should be the IObserver
* Dragon should be the ISubject - (the easiest way is to make ITarget extends ISubject, but this is
violation of the Interface Segregation Principle). The better solution is to create a new interface
ObservableTarget and implement both ITarget and IObserver.

© Software University Foundation. This work is licensed under the CC-BY-NC-SA license.

Follow us: Page 5 of 5

You might also like