Skip to content

Commit cf9c2f6

Browse files
author
sajith
committed
Improved
1 parent edeac60 commit cf9c2f6

16 files changed

+225
-0
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ project(SOLID)
33

44
set(CMAKE_CXX_STANDARD 20)
55
#add_subdirectory(plant-care)
6+
add_subdirectory(plant-care-better)
67

78
#add_executable(main main.cpp)
89

plant-care-better/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
}

plant-care-better/main/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
project(plantcare)
2+
3+
add_executable(${PROJECT_NAME} src/main.cpp)
4+
5+
target_link_libraries(${PROJECT_NAME} caretaker sensors)

plant-care-better/main/src/main.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//
2+
// Created by sajith on 4/20/21.
3+
//
4+
5+
#include <iostream>
6+
7+
int main()
8+
{
9+
10+
return 0;
11+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
//
2+
// Created by sajith on 4/20/21.
3+
//
4+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
//
2+
// Created by sajith on 4/20/21.
3+
//
4+

0 commit comments

Comments
 (0)