C++ features by examples
C++ OOP patterns

some examples in C++ More...

Classes

struct  Setter_interface< ValueType >
 
struct  Getter_interface< ValueType >
 
struct  Change_interface< ValueType >
 
class  Synchronised_encapsulated_value< ValueType >
 encapsulating class with only public accessor and mutator intrfaces More...
 

Functions

void oop_demo ()
 

Detailed Description

some examples in C++

Four Pillars of Object-oriented_programming:

object-oriented-programming-in-cpp

class

derived_class

abstract_class

shared_lock

Three independent interfaces Setter_interface, Getter_interface and Change_interface demonstrate Interface segregation

Function Documentation

◆ oop_demo()

void oop_demo ( )

Lambda expression 'client' demonstrates Dependency inversion - it doesn't depends from implementation Synchronised_encapsulated_value but depends only from interfaces.

Definition at line 115 of file patterns.cpp.

121{
122 auto client = [] (Setter_interface<int>& s, Getter_interface<int>& g) {
123 s.set(1);
124 assert(g.get() == 1);
125 };
129 client(s, g);
130
131 auto client2 = [] (Setter_interface<string>& s, Getter_interface<string>& g) {
132 s.set("abc");
133 assert(g.get() == "abc");
134 };
139 client2(s2, g2);
140 c2.change("de");
141 assert(g2.get() == "abcde");
142}
encapsulating class with only public accessor and mutator intrfaces
Definition: patterns.cpp:95
virtual ValueType get() const =0
is a sample of getter abstract interface for Synchronised_encapsulated_value
virtual void set(ValueType i)=0
is a sample of setter abstract interface for Synchronised_encapsulated_value
Here is the call graph for this function:
Here is the caller graph for this function: