File tree 16 files changed +225
-0
lines changed 16 files changed +225
-0
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ project(SOLID)
3
3
4
4
set (CMAKE_CXX_STANDARD 20)
5
5
#add_subdirectory(plant-care)
6
+ add_subdirectory (plant-care-better)
6
7
7
8
#add_executable(main main.cpp)
8
9
Original file line number Diff line number Diff line change
1
+ cmake_minimum_required (VERSION 3.10)
2
+
3
+ project (plantcare-better)
4
+
5
+ SET (CMAKE_CXX_FLAGS "-std=c++17 -pthread -O3 -pedantic -Wall -Werror" )
6
+
7
+ add_subdirectory (sensors)
8
+ add_subdirectory (caretaker)
9
+ add_subdirectory (main)
Original file line number Diff line number Diff line change
1
+ project (caretaker)
2
+
3
+ include_directories (${PROJECT_SOURCE_DIR} /include )
4
+
5
+ set (SOURCE
6
+ ${PROJECT_SOURCE_DIR} /include /caretaker/WaterDevice.h
7
+ ${PROJECT_SOURCE_DIR} /include /caretaker/WindowDevice.h
8
+ ${PROJECT_SOURCE_DIR} /include /caretaker/AloeCaretaker.h
9
+ ${PROJECT_SOURCE_DIR} /include /caretaker/CactusCaretaker.h
10
+ ${PROJECT_SOURCE_DIR} /src/AloeCaretaker.cpp
11
+ ${PROJECT_SOURCE_DIR} /src/CactusCaretaker.cpp
12
+ )
13
+
14
+ add_library (${PROJECT_NAME} STATIC ${SOURCE} )
15
+ target_include_directories (${PROJECT_NAME} PUBLIC ${PROJECT_SOURCE_DIR} /include )
Original file line number Diff line number Diff line change
1
+ //
2
+ // Created by sajith on 4/20/21.
3
+ //
4
+
5
+ #ifndef SOLID_ALOECARETAKER_H
6
+ #define SOLID_ALOECARETAKER_H
7
+
8
+ #include " caretaker/WaterDevice.h"
9
+ #include " caretaker/WindowDevice.h"
10
+
11
+ namespace caretaker
12
+ {
13
+ class AloeCaretaker : public interfaces ::WaterDevice, public interfaces::WindowDevice
14
+ {
15
+ bool windowBlindsOpen = true ;
16
+
17
+
18
+ public:
19
+ void pourWater () override ;
20
+ void sprinkleWater () override ;
21
+
22
+ void openWindowBlinds () override ;
23
+ void closeWindowBlinds () override ;
24
+ };
25
+ }
26
+
27
+ #endif // SOLID_ALOECARETAKER_H
Original file line number Diff line number Diff line change
1
+ //
2
+ // Created by sajith on 4/20/21.
3
+ //
4
+
5
+ #ifndef SOLID_CACTUSCARETAKER_H
6
+ #define SOLID_CACTUSCARETAKER_H
7
+
8
+ #include " caretaker/WaterDevice.h"
9
+
10
+ namespace caretaker
11
+ {
12
+ class CactusCaretaker : public interfaces ::WaterDevice
13
+ {
14
+ public:
15
+
16
+ void pourWater () override ;
17
+ void sprinkleWater () override ;
18
+ };
19
+ }
20
+
21
+ #endif // SOLID_CACTUSCARETAKER_H
Original file line number Diff line number Diff line change
1
+ //
2
+ // Created by sajith on 4/20/21.
3
+ //
4
+
5
+ #ifndef SOLID_WATERDEVICE_H
6
+ #define SOLID_WATERDEVICE_H
7
+
8
+ namespace interfaces
9
+ {
10
+ class WaterDevice
11
+ {
12
+ public:
13
+ virtual ~WaterDevice () = default ;
14
+ virtual void pourWater () = 0;
15
+ virtual void sprinkleWater () = 0;
16
+ };
17
+ }
18
+
19
+ #endif // SOLID_WATERDEVICE_H
Original file line number Diff line number Diff line change
1
+ //
2
+ // Created by sajith on 4/20/21.
3
+ //
4
+
5
+ #ifndef SOLID_WINDOWDEVICE_H
6
+ #define SOLID_WINDOWDEVICE_H
7
+
8
+ namespace interfaces
9
+ {
10
+ class WindowDevice
11
+ {
12
+ public:
13
+ virtual ~WindowDevice () = default ;
14
+
15
+ virtual void openWindowBlinds () = 0;
16
+ virtual void closeWindowBlinds () = 0;
17
+ };
18
+ }
19
+
20
+ #endif // SOLID_WINDOWDEVICE_H
Original file line number Diff line number Diff line change
1
+ //
2
+ // Created by sajith on 4/20/21.
3
+ //
4
+
5
+ #include < iostream>
6
+ #include " caretaker/AloeCaretaker.h"
7
+
8
+
9
+ namespace caretaker
10
+ {
11
+ void AloeCaretaker::pourWater ()
12
+ {
13
+ std::cout << " Pouring water on Aloe" << std::endl;
14
+ }
15
+
16
+ void AloeCaretaker::sprinkleWater ()
17
+ {
18
+ std::cout << " Sprinkling water on Aloe" << std::endl;
19
+ }
20
+
21
+ void AloeCaretaker::openWindowBlinds ()
22
+ {
23
+ if (not windowBlindsOpen)
24
+ {
25
+ windowBlindsOpen = true ;
26
+ std::cout << " Opened window blinds for Aloe" << std::endl;
27
+ }
28
+ }
29
+
30
+ void AloeCaretaker::closeWindowBlinds ()
31
+ {
32
+ if (windowBlindsOpen)
33
+ {
34
+ windowBlindsOpen = false ;
35
+ std::cout << " Closed window blinds for Aloe" << std::endl;
36
+ }
37
+ }
38
+ }
Original file line number Diff line number Diff line change
1
+ //
2
+ // Created by sajith on 4/20/21.
3
+ //
4
+
5
+ #include < iostream>
6
+
7
+ #include " caretaker/CactusCaretaker.h"
8
+
9
+
10
+ namespace caretaker
11
+ {
12
+ void CactusCaretaker::pourWater ()
13
+ {
14
+ std::cout << " Pouring water on Cactus" << std::endl;
15
+ }
16
+
17
+ void CactusCaretaker::sprinkleWater ()
18
+ {
19
+ std::cout << " Sprinkling water on Cactus" << std::endl;
20
+ }
21
+ }
Original file line number Diff line number Diff line change
1
+ project (plantcare)
2
+
3
+ add_executable (${PROJECT_NAME} src/main.cpp)
4
+
5
+ target_link_libraries (${PROJECT_NAME} caretaker sensors)
Original file line number Diff line number Diff line change
1
+ //
2
+ // Created by sajith on 4/20/21.
3
+ //
4
+
5
+ #include < iostream>
6
+
7
+ int main ()
8
+ {
9
+
10
+ return 0 ;
11
+ }
Original file line number Diff line number Diff line change
1
+ project (sensors)
2
+
3
+ include_directories (${PROJECT_SOURCE_DIR} /include )
4
+
5
+ set (SOURCE
6
+ ${PROJECT_SOURCE_DIR} /include /sensors/SunlightSensor.h
7
+ ${PROJECT_SOURCE_DIR} /include /sensors/MoistureSensor.h
8
+ ${PROJECT_SOURCE_DIR} /src/SunlightSensor.cpp
9
+ ${PROJECT_SOURCE_DIR} /src/MoistureSensor.cpp
10
+ )
11
+
12
+ add_library (${PROJECT_NAME} STATIC ${SOURCE} )
13
+ target_link_libraries (${PROJECT_NAME} caretaker)
14
+ target_include_directories (${PROJECT_NAME} PUBLIC ${PROJECT_SOURCE_DIR} /include )
Original file line number Diff line number Diff line change
1
+ //
2
+ // Created by sajith on 4/20/21.
3
+ //
4
+
5
+ #ifndef SOLID_MOISTURESENSOR_H
6
+ #define SOLID_MOISTURESENSOR_H
7
+
8
+ #endif //SOLID_MOISTURESENSOR_H
Original file line number Diff line number Diff line change
1
+ //
2
+ // Created by sajith on 4/20/21.
3
+ //
4
+
5
+ #ifndef SOLID_SUNLIGHTSENSOR_H
6
+ #define SOLID_SUNLIGHTSENSOR_H
7
+
8
+ #endif //SOLID_SUNLIGHTSENSOR_H
Original file line number Diff line number Diff line change
1
+ //
2
+ // Created by sajith on 4/20/21.
3
+ //
4
+
Original file line number Diff line number Diff line change
1
+ //
2
+ // Created by sajith on 4/20/21.
3
+ //
4
+
You can’t perform that action at this time.
0 commit comments