C++ features by examples

Behavioral patterns More...

Collaboration diagram for Behavioral:

Modules

 Visitor
 Visitor pattern
 

Classes

struct  Observer
 is virtual observer of a Subject More...
 
struct  Subject
 of Observer More...
 
struct  Command
 encapsulates arguments. AKA Intent, operation. More...
 
struct  Handler
 is a virtual command handler of Chain_of_responsibility More...
 
struct  Chain_of_responsibility
 list based implementation without recursion More...
 
struct  Message
 
struct  Member
 
struct  Mediator
 

Functions

void mediator_demo ()
 
void behavioral_patterns_demo ()
 
void Member::send (Message &)
 

Detailed Description

Behavioral patterns

https://refactoring.guru/design-patterns/behavioral-patterns

Function Documentation

◆ behavioral_patterns_demo()

void behavioral_patterns_demo ( )

Definition at line 594 of file patterns.cpp.

595{
597 chain.register_handler(Handler());
598
599 Command cmnd;
600 chain.handle(cmnd);
601
602 Observer o;
603 Subject s;
604 s.observers.push_front(o);
605
606 visitor_demo();
607
609}
void mediator_demo()
Definition: patterns.cpp:584
void visitor_demo()
Definition: patterns.cpp:491
list based implementation without recursion
Definition: patterns.cpp:531
int handle(Command &cmnd) override
Specific handler can process a command and return non-negative.
Definition: patterns.cpp:538
void register_handler(Handler &&h, bool front=false)
Definition: patterns.cpp:532
encapsulates arguments. AKA Intent, operation.
Definition: patterns.cpp:423
is a virtual command handler of Chain_of_responsibility
Definition: patterns.cpp:516
is virtual observer of a Subject
Definition: patterns.cpp:396
of Observer
Definition: patterns.cpp:406
forward_list< reference_wrapper< Observer > > observers
Definition: patterns.cpp:413
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mediator_demo()

void mediator_demo ( )

Definition at line 584 of file patterns.cpp.

585{
586 Member m1, m2;
587 Mediator md;
588 md.register_member(m1);
589 md.register_member(m2);
590 Message msg;
591 m1.send(msg);
592}
void send(Message &)
Definition: patterns.cpp:579
void register_member(Member &m)
Definition: patterns.cpp:568
Here is the call graph for this function:
Here is the caller graph for this function:

◆ send()

void Member::send ( Message m)

Definition at line 579 of file patterns.cpp.

580{
581 mediator->receive(m);
582}
void receive(Message &msg)
Definition: patterns.cpp:572
Mediator * mediator
Definition: patterns.cpp:561
Here is the call graph for this function:
Here is the caller graph for this function: