OPENIT2 Telegram 3310
πŸ€ΠŸΠ°Ρ‚Π΅Ρ€Π½ програмування Mediator πŸ•ŠοΈ

Π”ΠΎΠΏΠΎΠΌΠ°Π³Π°Ρ” Π·ΠΌΠ΅Π½ΡˆΠΈΡ‚ΠΈ ΠΊΡ–Π»ΡŒΠΊΡ–ΡΡ‚ΡŒ залСТностСй ΠΌΡ–ΠΆ ΠΎΠ±'Ρ”ΠΊΡ‚Π°ΠΌΠΈ ΠΉ Ρ€ΠΎΠ±ΠΈΡ‚ΡŒ Ρ—Ρ…Π½ΡŽ Π²Π·Π°Ρ”ΠΌΠΎΠ΄Ρ–ΡŽ Ρ†Π΅Π½Ρ‚Ρ€Π°Π»Ρ–Π·ΠΎΠ²Π°Π½ΠΎΡŽ Ρ‡Π΅Ρ€Π΅Π· ΡΠΏΠ΅Ρ†Ρ–Π°Π»ΡŒΠ½ΠΈΠΉ ΠΎΠ±'Ρ”ΠΊΡ‚ β€” ΠΌΠ΅Π΄Ρ–Π°Ρ‚ΠΎΡ€. 🌐

Mediator дозволяє Π³Ρ€ΡƒΠΏΡ– ΠΎΠ±'Ρ”ΠΊΡ‚Ρ–Π² спілкуватися Ρ‡Π΅Ρ€Π΅Π· Ρ†Π΅Π½Ρ‚Ρ€Π°Π»ΡŒΠ½ΠΈΠΉ ΠΎΠ±'Ρ”ΠΊΡ‚. Π—Π°ΠΌΡ–ΡΡ‚ΡŒ Ρ‚ΠΎΠ³ΠΎ, Ρ‰ΠΎΠ± ΠΎΠ±'Ρ”ΠΊΡ‚ΠΈ напряму Π²ΠΈΠΊΠ»ΠΈΠΊΠ°Π»ΠΈ ΠΌΠ΅Ρ‚ΠΎΠ΄ΠΈ ΠΎΠ΄ΠΈΠ½ ΠΎΠ΄Π½ΠΎΠ³ΠΎ, Π²ΠΎΠ½ΠΈ Π²ΠΈΠΊΠ»ΠΈΠΊΠ°ΡŽΡ‚ΡŒ ΠΌΠ΅Ρ‚ΠΎΠ΄ΠΈ ΠΌΠ΅Π΄Ρ–Π°Ρ‚ΠΎΡ€Π°, який ΠΏΠΎΡ‚Ρ–ΠΌ ΠΊΠ΅Ρ€ΡƒΡ” Ρ—Ρ…Π½ΡŽ Π²Π·Π°Ρ”ΠΌΠΎΠ΄Ρ–Ρ”ΡŽ. πŸ“‘

ΠŸΡ€ΠΈΠΊΠ»Π°Π΄ ΠΊΠΎΠ΄Ρƒ Π½Π° Python

class Mediator:
def notify(self, sender, event):
pass

class ConcreteMediator(Mediator):
def init(self, component1, component2):
self._component1 = component1
self._component1.mediator = self
self._component2 = component2
self._component2.mediator = self

def notify(self, sender, event):
if event == "A":
print("Mediator reacts on A and triggers following operations:")
self._component2.do_c()
elif event == "D":
print("Mediator reacts on D and triggers following operations:")
self._component1.do_b()
self._component2.do_c()

class BaseComponent:
def init(self, mediator=None):
self._mediator = mediator

@property
def mediator(self):
return self._mediator

@mediator.setter
def mediator(self, mediator):
self._mediator = mediator

class Component1(BaseComponent):
def do_a(self):
print("Component 1 does A.")
self.mediator.notify(self, "A")

def do_b(self):
print("Component 1 does B.")

class Component2(BaseComponent):
def do_c(self):
print("Component 2 does C.")

def do_d(self):
print("Component 2 does D.")
self.mediator.notify(self, "D")

if name == "main":
component1 = Component1()
component2 = Component2()
mediator = ConcreteMediator(component1, component2)

print("Client triggers operation A.")
component1.do_a()

print("\nClient triggers operation D.")
component2.do_d()


πŸ—ΠŸΠΎΡΡΠ½Π΅Π½Π½ΡπŸ—
1. Mediator β€” Π±Π°Π·ΠΎΠ²ΠΈΠΉ клас, який Π²ΠΈΠ·Π½Π°Ρ‡Π°Ρ” ΠΌΠ΅Ρ‚ΠΎΠ΄ Β«notifyΒ».
2. ConcreteMediator β€” ΠΌΠ΅Π΄Ρ–Π°Ρ‚ΠΎΡ€, який Π·Π½Π°Ρ” ΠΏΡ€ΠΎ всі ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ΠΈ ΠΉ ΠΊΠ΅Ρ€ΡƒΡ” Ρ—Ρ…Π½Π΅ΡŽ Π²Π·Π°Ρ”ΠΌΠΎΠ΄Ρ–Ρ”ΡŽ.
3. BaseComponent β€” Π±Π°Π·ΠΎΠ²ΠΈΠΉ клас для ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚Ρ–Π², які ΠΌΠ°ΡŽΡ‚ΡŒ посилання Π½Π° ΠΌΠ΅Π΄Ρ–Π°Ρ‚ΠΎΡ€Π°.
4. Component1 Ρ– Component2 β€” ΠΊΠΎΠ½ΠΊΡ€Π΅Ρ‚Π½Ρ– ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ΠΈ, які Π²ΠΈΠΊΠΎΠ½ΡƒΡŽΡ‚ΡŒ свої Π΄Ρ–Ρ— Ρ‚Π° ΠΏΠΎΠ²Ρ–Π΄ΠΎΠΌΠ»ΡΡŽΡ‚ΡŒ ΠΌΠ΅Π΄Ρ–Π°Ρ‚ΠΎΡ€Π° ΠΏΡ€ΠΎ ΠΏΠΎΠ΄Ρ–Ρ—.

Π£ Ρ†ΡŒΠΎΠΌΡƒ ΠΏΡ€ΠΈΠΊΠ»Π°Π΄Ρ– ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ 1 Π²ΠΈΠΊΠ»ΠΈΠΊΠ°Ρ” ΠΏΠΎΠ΄Ρ–ΡŽ Β«AΒ», яку ΠΌΠ΅Π΄Ρ–Π°Ρ‚ΠΎΡ€ ΠΏΠ΅Ρ€Π΅Ρ…ΠΎΠΏΠ»ΡŽΡ” Ρ– Π²ΠΈΠΊΠ»ΠΈΠΊΠ°Ρ” ΠΌΠ΅Ρ‚ΠΎΠ΄ Β«do_cΒ» ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚Π° 2. Аналогічно, подія Β«DΒ» ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚Π° 2 Π²ΠΈΠΊΠ»ΠΈΠΊΠ°Ρ” ΠΌΠ΅Ρ‚ΠΎΠ΄ΠΈ Β«do_bΒ» ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚Π° 1 Ρ– Β«do_cΒ» ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚Π° 2. πŸ”„

#CodeBreakdown_for_students

πŸ‘‰ IT Student β€” Π±ΡƒΠ΄ΡŒ Π² курсі IT-моТливостСй для Ρ‚Π΅Π±Π΅!



tgoop.com/openit2/3310
Create:
Last Update:

πŸ€ΠŸΠ°Ρ‚Π΅Ρ€Π½ програмування Mediator πŸ•ŠοΈ

Π”ΠΎΠΏΠΎΠΌΠ°Π³Π°Ρ” Π·ΠΌΠ΅Π½ΡˆΠΈΡ‚ΠΈ ΠΊΡ–Π»ΡŒΠΊΡ–ΡΡ‚ΡŒ залСТностСй ΠΌΡ–ΠΆ ΠΎΠ±'Ρ”ΠΊΡ‚Π°ΠΌΠΈ ΠΉ Ρ€ΠΎΠ±ΠΈΡ‚ΡŒ Ρ—Ρ…Π½ΡŽ Π²Π·Π°Ρ”ΠΌΠΎΠ΄Ρ–ΡŽ Ρ†Π΅Π½Ρ‚Ρ€Π°Π»Ρ–Π·ΠΎΠ²Π°Π½ΠΎΡŽ Ρ‡Π΅Ρ€Π΅Π· ΡΠΏΠ΅Ρ†Ρ–Π°Π»ΡŒΠ½ΠΈΠΉ ΠΎΠ±'Ρ”ΠΊΡ‚ β€” ΠΌΠ΅Π΄Ρ–Π°Ρ‚ΠΎΡ€. 🌐

Mediator дозволяє Π³Ρ€ΡƒΠΏΡ– ΠΎΠ±'Ρ”ΠΊΡ‚Ρ–Π² спілкуватися Ρ‡Π΅Ρ€Π΅Π· Ρ†Π΅Π½Ρ‚Ρ€Π°Π»ΡŒΠ½ΠΈΠΉ ΠΎΠ±'Ρ”ΠΊΡ‚. Π—Π°ΠΌΡ–ΡΡ‚ΡŒ Ρ‚ΠΎΠ³ΠΎ, Ρ‰ΠΎΠ± ΠΎΠ±'Ρ”ΠΊΡ‚ΠΈ напряму Π²ΠΈΠΊΠ»ΠΈΠΊΠ°Π»ΠΈ ΠΌΠ΅Ρ‚ΠΎΠ΄ΠΈ ΠΎΠ΄ΠΈΠ½ ΠΎΠ΄Π½ΠΎΠ³ΠΎ, Π²ΠΎΠ½ΠΈ Π²ΠΈΠΊΠ»ΠΈΠΊΠ°ΡŽΡ‚ΡŒ ΠΌΠ΅Ρ‚ΠΎΠ΄ΠΈ ΠΌΠ΅Π΄Ρ–Π°Ρ‚ΠΎΡ€Π°, який ΠΏΠΎΡ‚Ρ–ΠΌ ΠΊΠ΅Ρ€ΡƒΡ” Ρ—Ρ…Π½ΡŽ Π²Π·Π°Ρ”ΠΌΠΎΠ΄Ρ–Ρ”ΡŽ. πŸ“‘

ΠŸΡ€ΠΈΠΊΠ»Π°Π΄ ΠΊΠΎΠ΄Ρƒ Π½Π° Python

class Mediator:
def notify(self, sender, event):
pass

class ConcreteMediator(Mediator):
def init(self, component1, component2):
self._component1 = component1
self._component1.mediator = self
self._component2 = component2
self._component2.mediator = self

def notify(self, sender, event):
if event == "A":
print("Mediator reacts on A and triggers following operations:")
self._component2.do_c()
elif event == "D":
print("Mediator reacts on D and triggers following operations:")
self._component1.do_b()
self._component2.do_c()

class BaseComponent:
def init(self, mediator=None):
self._mediator = mediator

@property
def mediator(self):
return self._mediator

@mediator.setter
def mediator(self, mediator):
self._mediator = mediator

class Component1(BaseComponent):
def do_a(self):
print("Component 1 does A.")
self.mediator.notify(self, "A")

def do_b(self):
print("Component 1 does B.")

class Component2(BaseComponent):
def do_c(self):
print("Component 2 does C.")

def do_d(self):
print("Component 2 does D.")
self.mediator.notify(self, "D")

if name == "main":
component1 = Component1()
component2 = Component2()
mediator = ConcreteMediator(component1, component2)

print("Client triggers operation A.")
component1.do_a()

print("\nClient triggers operation D.")
component2.do_d()


πŸ—ΠŸΠΎΡΡΠ½Π΅Π½Π½ΡπŸ—
1. Mediator β€” Π±Π°Π·ΠΎΠ²ΠΈΠΉ клас, який Π²ΠΈΠ·Π½Π°Ρ‡Π°Ρ” ΠΌΠ΅Ρ‚ΠΎΠ΄ Β«notifyΒ».
2. ConcreteMediator β€” ΠΌΠ΅Π΄Ρ–Π°Ρ‚ΠΎΡ€, який Π·Π½Π°Ρ” ΠΏΡ€ΠΎ всі ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ΠΈ ΠΉ ΠΊΠ΅Ρ€ΡƒΡ” Ρ—Ρ…Π½Π΅ΡŽ Π²Π·Π°Ρ”ΠΌΠΎΠ΄Ρ–Ρ”ΡŽ.
3. BaseComponent β€” Π±Π°Π·ΠΎΠ²ΠΈΠΉ клас для ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚Ρ–Π², які ΠΌΠ°ΡŽΡ‚ΡŒ посилання Π½Π° ΠΌΠ΅Π΄Ρ–Π°Ρ‚ΠΎΡ€Π°.
4. Component1 Ρ– Component2 β€” ΠΊΠΎΠ½ΠΊΡ€Π΅Ρ‚Π½Ρ– ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ΠΈ, які Π²ΠΈΠΊΠΎΠ½ΡƒΡŽΡ‚ΡŒ свої Π΄Ρ–Ρ— Ρ‚Π° ΠΏΠΎΠ²Ρ–Π΄ΠΎΠΌΠ»ΡΡŽΡ‚ΡŒ ΠΌΠ΅Π΄Ρ–Π°Ρ‚ΠΎΡ€Π° ΠΏΡ€ΠΎ ΠΏΠΎΠ΄Ρ–Ρ—.

Π£ Ρ†ΡŒΠΎΠΌΡƒ ΠΏΡ€ΠΈΠΊΠ»Π°Π΄Ρ– ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ 1 Π²ΠΈΠΊΠ»ΠΈΠΊΠ°Ρ” ΠΏΠΎΠ΄Ρ–ΡŽ Β«AΒ», яку ΠΌΠ΅Π΄Ρ–Π°Ρ‚ΠΎΡ€ ΠΏΠ΅Ρ€Π΅Ρ…ΠΎΠΏΠ»ΡŽΡ” Ρ– Π²ΠΈΠΊΠ»ΠΈΠΊΠ°Ρ” ΠΌΠ΅Ρ‚ΠΎΠ΄ Β«do_cΒ» ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚Π° 2. Аналогічно, подія Β«DΒ» ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚Π° 2 Π²ΠΈΠΊΠ»ΠΈΠΊΠ°Ρ” ΠΌΠ΅Ρ‚ΠΎΠ΄ΠΈ Β«do_bΒ» ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚Π° 1 Ρ– Β«do_cΒ» ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚Π° 2. πŸ”„

#CodeBreakdown_for_students

πŸ‘‰ IT Student β€” Π±ΡƒΠ΄ΡŒ Π² курсі IT-моТливостСй для Ρ‚Π΅Π±Π΅!

BY IT Student by Kharkiv IT Cluster


Share with your friend now:
tgoop.com/openit2/3310

View MORE
Open in Telegram


Telegram News

Date: |

Step-by-step tutorial on desktop: How to create a business channel on Telegram? (Tutorial) During the meeting with TSE Minister Edson Fachin, Perekopsky also mentioned the TSE channel on the platform as one of the firm's key success stories. Launched as part of the company's commitments to tackle the spread of fake news in Brazil, the verified channel has attracted more than 184,000 members in less than a month. The imprisonment came as Telegram said it was "surprised" by claims that privacy commissioner Ada Chung Lai-ling is seeking to block the messaging app due to doxxing content targeting police and politicians. Telegram offers a powerful toolset that allows businesses to create and manage channels, groups, and bots to broadcast messages, engage in conversations, and offer reliable customer support via bots.
from us


Telegram IT Student by Kharkiv IT Cluster
FROM American