单一职责模式

一个类就只做一件事情。

 1 #define  _CRT_SECURE_NO_WARNINGS 
 2 #include <iostream>
 3 
 4 using namespace std;
 5 
 6 
 7 #if 0
 8 class Clothes
 9 {
10 public:
11     void shopping() {
12         cout << "休闲的服装" << endl;
13     }
14     void working() {
15         cout << "休闲的服装" << endl;
16     }
17 };
18 #endif
19 
20 class ClothesShpping
21 {
22 public:
23     void style() {
24         cout << "休闲的服装" << endl;
25     }
26 };
27 class ClothesWorking
28 {
29 public:
30     void style() {
31         cout << "休闲的服装" << endl;
32     }
33 };
34 
35 int main(void)
36 {
37 #if 0
38     Clothes c1;
39     c1.shopping();
40 
41     c1.shopping();
42 #endif
43     ClothesShpping cs; 
44     cs.style();
45 
46     ClothesWorking cw;
47     cw.style();
48     
49     return 0;
50 }

 

posted @ 2020-03-22 09:22  撑雨伞的小男孩  阅读(123)  评论(0编辑  收藏  举报