Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ set(APP_SOURCES
"src/patterns/creational/AbstractFactory.cpp"
"src/patterns/creational/Builder.cpp"
"src/patterns/creational/Prototype.cpp"
"src/core/datatypes/class/Relationship.cpp"
## Exceptions
"src/core/exception/BasicHandle.cpp"
"src/core/exception/ThrowNoexcept.cpp"
Expand Down
22 changes: 9 additions & 13 deletions src/cembedded/README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
# 1. Core C Basics for Embedded Systems

```
Your Foundation for Embedded Programming
```
**Topics Covered:**

- Variables & Data Types
- Operators & Control Flow
- Functions
- Arrays & Strings
- Basic Input/Output
- Practice Problems
- 1.1 Variables & Data Types
- 1.2 Operators & Control Flow
- 1.3 Functions
- 1.4 Arrays & Strings
- 1.5 Basic Input/Output
- 1.6 Practice Problems

## 1.1 Variables & Data Types

Expand Down Expand Up @@ -268,10 +265,12 @@ printf("Hello %s, you are %d years old!\n", name, age);

**Common Format Specifiers**

| Specifier | Data Type | Example |
| Specifier | Data Type | Example |
|---------------|----------------|------------------------------|
| %d or %i | int | printf("%d", 42); |
| %ld | long | printf("%lu", 255); |
| %u | unsigned int | printf("%u", 255); |
| %lu | uint32_t | printf("%lu", 255); |
| %f | float/double | printf("%.2f", 3.14); |
| %c | char | printf("%c", 'A'); |
| %s | string | printf("%s", "Hello"); |
Expand All @@ -281,9 +280,6 @@ printf("Hello %s, you are %d years old!\n", name, age);

## 1.6. Practice Problems

Here are some hands-on exercises to solidify your understanding. Try to solve these
without looking at solutions first!

**Problem 1: Temperature Converter**

Write a program that converts temperature from Celsius to Fahrenheit using the
Expand Down
251 changes: 250 additions & 1 deletion src/core/datatypes/class/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,253 @@ operator OP (type_of_X, type_of_Y)
- It give access to only once specific function.
### 1.3. Class
- Friend Class : I trust this class to see my private data
- It give access to all member functions of another class.
- It give access to all member functions of another class.

## 2. Class Relationship
### 2.1. Composition
- **Part-of, strong ownership**
- The member is part of the class
- The member can only belong to one class at a time
- The member has its existence managed by the class
- The member does not know about the existence of the class

- UML:
```cpp
+------------------------+
| Car |
+------------------------+
| - engine : Engine |
+------------------------+
+------------------------+
| Engine |
+------------------------+
| + Engine() |
| + ~Engine() |
+------------------------+

class Engine
{
public:
Engine() { std::cout << "Engine created\n"; }
~Engine() { std::cout << "Engine destroyed\n"; }
};

class Car
{
private:
Engine engine; // composition

public:
Car() { std::cout << "Car created\n"; }
~Car() { std::cout << "Car destroyed\n"; }
};
```

## 2.2. Aggregations
- **Has-a, weak ownership**
- The member is part of the class
- The member can belong to more than one class at a time
- The member does not have its existence managed by the class
- The member does not know about the existence of the class

- UML:
```cpp
+-----------------------------+
| Department |
+-----------------------------+
| - teacher : Teacher* |
+-----------------------------+
+-----------------------------+
| Teacher |
+-----------------------------+
| - name : std::string |
+-----------------------------+

class Teacher
{
public:
std::string name;
Teacher(const std::string& n) : name(n) {}
};

class Department
{
private:
Teacher* teacher; // aggregation

public:
Department(Teacher* t) : teacher(t) {}
};
```

## 2.3. Associations
- **Uses-a, loose relationship**
- The associated member is otherwise unrelated to the class
- The associated member can belong to more than one class at a time
- The associated member does not have its existence managed by the class
- The associated member may or may not know about the existence of the class
- UML
```cpp
+---------------------+ +---------------------+
| Doctor |-----------------| Patient |
+---------------------+ +---------------------+
| + treat(p:Patient&) | | - name : string |
+---------------------+ +---------------------+

class Patient
{
public:
std::string name;
};

class Doctor
{
public:
void treat(Patient& p)
{
std::cout << "Treating " << p.name << "\n";
}
};
```

## 2.4. Dependency
- **Denpends-on**
- One class uses another class to perform a task.
- It is temporarily created, used, and then destroyed, or passed into a member function from an external source.
- UML
```cpp
+---------------------+
| Car |
+---------------------+
| + start() |
+---------------------+
- - - - - - - - - - - - - - - - - - >
+---------------------+
| Logger |
+---------------------+
| + log(msg:string) |
+---------------------+
class Logger
{
public:
void log(const std::string& msg)
{
std::cout << msg << std::endl;
}
};

class Car
{
public:
void start()
{
Logger logger; // dependency
logger.log("Car started");
}
};

```
## 2.5. Container
- The class one class provides a container to hold multiple objects of another type
- UML
```cpp
#include <vector>

+-----------------------------+
| Library1 |
+-----------------------------+
| - books : vector<string> |
+-----------------------------+
+-----------------------------+
| string |
+-----------------------------+
class Library1
{
private:
std::vector<std::string> books; // copy values
};

+-----------------------------+
| Library2 |
+-----------------------------+
| - teachers : vector<T*> |
+-----------------------------+
+-----------------------------+
| Teacher |
+-----------------------------+
class Library2
{
private:
std::vector<Teacher*> teachers; // store pointers
};

```

## 2.6. Inheritance
- **Is-a**
```cpp
+----------------------+
| Animal |
+----------------------+
| + eat() |
+----------------------+
+----------------------+
| Dog |
+----------------------+
| + bark() |
+----------------------+
class Animal
{
public:
void eat() { std::cout << "Eating\n"; }
};

class Dog : public Animal
{
public:
void bark() { std::cout << "Woof\n"; }
};
```

## 2.7 Embedded a.k.a Nested/Inner Class
- Type-level containment
```cpp
+----------------------+
| Car |
+----------------------+
| |
+----------------------+
(+)
+----------------------+
| Engine |
+----------------------+
| + start() |
+----------------------+

class Car
{
public:
class Engine
{
public:
void start();
};
};
```
Loading