0
0
Software Engineeringknowledge~10 mins

Behavioral patterns (Observer, Strategy, Command) in Software Engineering - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define the Observer interface method name.

Software Engineering
class Observer:
    def [1](self, message):
        pass
Drag options to blanks, or click blank then click option'
Aexecute
Bhandle
Cnotify
Dupdate
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'notify' instead of 'update' as the method name.
2fill in blank
medium

Complete the code to select the correct Strategy interface method name.

Software Engineering
class Strategy:
    def [1](self, data):
        pass
Drag options to blanks, or click blank then click option'
Aexecute
Brun
Cupdate
Dnotify
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing with 'run' or 'update' which are less common.
3fill in blank
hard

Fix the error in the Command pattern method name for executing a command.

Software Engineering
class Command:
    def [1](self):
        pass
Drag options to blanks, or click blank then click option'
Aupdate
Brun
Cexecute
Dnotify
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'run' or 'update' which are not standard for Command pattern.
4fill in blank
hard

Fill both blanks to complete the Observer pattern subject notifying observers.

Software Engineering
class Subject:
    def __init__(self):
        self.observers = []

    def attach(self, observer):
        self.observers.append(observer)

    def notify_observers(self, message):
        for observer in self.observers:
            observer.[1](message)

subject = Subject()
subject.[2](observer_instance)
Drag options to blanks, or click blank then click option'
Aupdate
Bnotify
Cattach
Dexecute
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'notify' instead of 'update' for observer method.
Using 'notify' instead of 'attach' to add observers.
5fill in blank
hard

Fill all three blanks to complete a Strategy pattern example selecting and running a strategy.

Software Engineering
class Context:
    def __init__(self, strategy):
        self.strategy = strategy

    def set_strategy(self, [1]):
        self.strategy = [2]

    def execute_strategy(self, data):
        return self.strategy.[3](data)
Drag options to blanks, or click blank then click option'
Astrategy
Cexecute
Dupdate
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'update' instead of 'execute' for the strategy method.