feature: add lowering coupling discussions and methods.
parent
a206c10a5c
commit
8071fabb51
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"files.associations": {
|
||||
"iosfwd": "cpp"
|
||||
}
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 22 KiB |
Binary file not shown.
After Width: | Height: | Size: 18 KiB |
|
@ -0,0 +1,41 @@
|
|||
#include <iostream>
|
||||
|
||||
#define ON true
|
||||
#define OFF false
|
||||
|
||||
class Object
|
||||
{
|
||||
virtual ~Object(){}
|
||||
virtual void on() = 0;
|
||||
virtual void off() = 0;
|
||||
};
|
||||
|
||||
class Lamp : public Object
|
||||
{
|
||||
public:
|
||||
void on() override {
|
||||
// ...
|
||||
}
|
||||
void off() override {
|
||||
// ...
|
||||
}
|
||||
};
|
||||
|
||||
class Button
|
||||
{
|
||||
public:
|
||||
Button(Object& obj): mObj(obj){}
|
||||
void touch() {
|
||||
if (mState == ON) {
|
||||
mState = OFF;
|
||||
mObj.off();
|
||||
}
|
||||
else {
|
||||
mState = ON;
|
||||
mObj.on();
|
||||
}
|
||||
}
|
||||
private:
|
||||
Object* mObj;
|
||||
bool mState;
|
||||
};
|
|
@ -0,0 +1,34 @@
|
|||
#include <iostream>
|
||||
|
||||
#define ON true
|
||||
#define OFF false
|
||||
|
||||
class Lamp
|
||||
{
|
||||
public:
|
||||
void on() {
|
||||
// ...
|
||||
}
|
||||
void off() {
|
||||
// ...
|
||||
}
|
||||
};
|
||||
|
||||
class Button
|
||||
{
|
||||
public:
|
||||
Button(Lamp& lamp): mLamp(lamp){}
|
||||
void touch() {
|
||||
if (mState == ON) {
|
||||
mState = OFF;
|
||||
mLamp.off();
|
||||
}
|
||||
else {
|
||||
mState = ON;
|
||||
mLamp.on();
|
||||
}
|
||||
}
|
||||
private:
|
||||
Lamp& mLamp;
|
||||
bool mState;
|
||||
};
|
Loading…
Reference in New Issue