- Introduction
- Design Patterns Used in This Repository
- Folder Structure and Purpose
- System Architecture Overview
- Setting Up the Environment to Build This Repository
This project demonstrates the application of pattern-oriented software design principles in C++. It includes implementations of various design patterns to manage shapes and their operations.
Design Patterns are models of code that solve classic problems. They are solutions to software design problems that you can find in a real-world application. A Design Pattern is not a code that is ready to be used in your application, but it is a model that you can use to solve a problem. Design patterns are language neutral, so they can be applied to any language that supports object-orientation.
This repository demonstrates the use of several design patterns to solve common software design problems. Below is a list of the design patterns implemented:
-
Composite Pattern
- Used to represent and manage compound shapes that can contain other shapes. This allows treating individual shapes and groups of shapes uniformly.
-
Visitor Pattern
- Enables operations (like calculating area or generating info) to be performed on shapes without modifying their classes.
-
Iterator Pattern
- Provides a way to traverse shapes in a compound structure, such as iterating through the components of a compound shape.
-
Builder Pattern
- Used to construct shapes and compound shapes incrementally, providing a flexible way to create complex objects.
-
Filter Pattern
- Allows filtering shapes based on specific criteria, such as area, perimeter, or type.
These patterns are implemented in the src/ folder and are tested extensively in the test/ folder.
This folder contains the core implementation of the project, including:
- Shape Classes: Represent individual shapes like rectangles, ellipses, and triangles.
- CompoundShape: Implements the Composite Pattern to manage groups of shapes.
- Visitors: Implements the Visitor Pattern for operations like calculating area and generating info.
- Iterators: Implements the Iterator Pattern to traverse shapes in a compound structure.
- Filters: Implements the Filter Pattern to filter shapes based on criteria like area, perimeter, or type.
- Builders: Implements the Builder Pattern to construct shapes and compound shapes incrementally.
- Utilities: Provides helper functions for shape management and filtering.
This folder contains unit tests for all major components of the project. It uses Google Test to validate the functionality of:
- Shape classes (e.g.,
ut_rectangle.h,ut_ellipse.h,ut_triangle.h) - Compound shapes (
ut_compound_shape.h) - Visitors (
ut_visitor.h) - Iterators (
ut_iterator.h) - Filters (
ut_filter.h) - Builders (
ut_shape_builder.h) - Parsers (
ut_shape_parser.h) - Sorting (
ut_sort.h) - Terminal interaction (
ut_terminal.h)
This folder stores the compiled binaries of the project.
This folder stores the compiled object files (.o) generated during the build process.
makefile: Automates the build process, including compilation and testing.README.md: Provides documentation for the project.input.txt: Example input file for testing or demonstration purposes.
graph TD
A[Main Program] -->|Input Parsing| B[ShapeParser]
B -->|Build Shapes| C[ShapeBuilder]
C -->|Create Shapes| D[Shapes]
D -->|Composite Pattern| E[CompoundShape]
D -->|Visitor Pattern| F[Visitors]
D -->|Iterator Pattern| G[Iterators]
D -->|Filter Pattern| H[Filters]
E -->|Manage Shapes| I[Shape Collection]
F -->|Calculate Area| J[AreaVisitor]
F -->|Generate Info| K[InfoVisitor]
G -->|Traverse Shapes| L[ShapeIterator]
H -->|Filter Shapes| M[ShapeFilter]
M -->|Apply Filters| N[ShapeSetter]
This diagram illustrates the relationships between the main components and the design patterns used in the repository.
If you are starting with a fresh operating system, follow these steps to set up the required tools and dependencies to build and run this repository.
-
Install
makemakeis required to build the project using the providedmakefile.- On Ubuntu (or WSL):
sudo apt update sudo apt install make
- On Windows, you can install
makevia MinGW or Cygwin.
-
Install
g++- A C++ compiler is required to compile the source code.
- On Ubuntu (or WSL):
sudo apt install g++
- On Windows, you can install
g++via MinGW or WSL.
-
Install CMake
- CMake is required to build Google Test and other CMake-based tools.
- On Ubuntu (or WSL):
sudo apt install cmake
- On Windows, download and install CMake from cmake.org.
-
Install Google Test (gtest)
- Google Test is required to run the unit tests.
- On Ubuntu (or WSL):
sudo apt install libgtest-dev cd /usr/src/gtest sudo cmake . sudo make sudo cp *.a /usr/lib
- On Windows, you can use
vcpkgto install Google Test:
git clone https://github.com/microsoft/vcpkg.git cd vcpkg .\bootstrap-vcpkg.bat .\vcpkg.exe install gtest
-
Clone the repository:
git clone https://github.com/zidane0000/POSD.git cd POSD -
Build the project:
make
-
Run the tests:
./bin/ut_main
To clean up the build artifacts, run:
make clean