CSCIENCE1 Telegram 3131
Паттерн Command

Command позволяет инкапсулировать запрос как объект, что позволяет параметризовать клиентские объекты с различными запросами, ставить запросы в очередь и поддерживать отмену операций.

Пример:
Представьте, что у вас есть интерфейс для управления светом. С помощью паттерна Command вы можете создать команды для включения и выключения света.

class Light:
def turn_on(self):
print("Свет включен")

def turn_off(self):
print("Свет выключен")

class Command:
def execute(self):
pass

class TurnOnCommand(Command):
def __init__(self, light):
self.light = light

def execute(self):
self.light.turn_on()

class TurnOffCommand(Command):
def __init__(self, light):
self.light = light

def execute(self):
self.light.turn_off()



tgoop.com/CScience1/3131
Create:
Last Update:

Паттерн Command

Command позволяет инкапсулировать запрос как объект, что позволяет параметризовать клиентские объекты с различными запросами, ставить запросы в очередь и поддерживать отмену операций.

Пример:
Представьте, что у вас есть интерфейс для управления светом. С помощью паттерна Command вы можете создать команды для включения и выключения света.

class Light:
def turn_on(self):
print("Свет включен")

def turn_off(self):
print("Свет выключен")

class Command:
def execute(self):
pass

class TurnOnCommand(Command):
def __init__(self, light):
self.light = light

def execute(self):
self.light.turn_on()

class TurnOffCommand(Command):
def __init__(self, light):
self.light = light

def execute(self):
self.light.turn_off()

BY Computer Science


Share with your friend now:
tgoop.com/CScience1/3131

View MORE
Open in Telegram


Telegram News

Date: |

How to Create a Private or Public Channel on Telegram? During a meeting with the president of the Supreme Electoral Court (TSE) on June 6, Telegram's Vice President Ilya Perekopsky announced the initiatives. According to the executive, Brazil is the first country in the world where Telegram is introducing the features, which could be expanded to other countries facing threats to democracy through the dissemination of false content. 1What is Telegram Channels? Telegram channels fall into two types: Telegram Android app: Open the chats list, click the menu icon and select “New Channel.”
from us


Telegram Computer Science
FROM American