# iv - 3

## Clean Code

### software = build a house

1. basic = building plan.
2. build different purpose: apartment, hotel, business, etc.
3. goal: build house, and make customer happy.

TDD = possible to optimize parts of codes, not full redo.

## OOP

`inheritance, encapsulation, polymorphism`

#### Inheritance

mixin = multiple inheritance

put common methods, attributes to ancestor

#### Encapsulation

1. restricting direct access to some

```cpp
class Base {
    public:
        int publicMember;
    protected:
        int protectedMember;
    private:
        int privateMember;
};
```

* Everything that is aware of Base is also aware that Base contains publicMember.
* Only the children (and their children) are aware that Base contains protectedMember.
* No one but Base is aware of privateMember.

#### Polymorphism

* Different vendors design chips base on the same interface.
* interface = every animal has `eat()` **method**, no matter it is mammal or insect.

### Overload & override

overload = same scope, run-time-polymorphism

override = inheritance, same signature, compile-time-polymorphism

## FP

#### pure function, declarative, higher order function

immutable variable = no variable lock, and you will not encounter deadlock. = No wife, no divorce.

declarative = what to do, not how to do.

hof = input fn as params and output params, and wrap more properties.

### SOLID

Single Responsibility Principle

1. one module one role
2. separate data & logic

Open-Closed Principle = report display and printing should be 2 classes.

Liskov Substitution Principle = when using parent class, use child class.

Interface Segregation Principle (ISP)

1. separate data & logic
2. A rely on B, and B rely on C. A and B will be changed when changing C

Dependency Inversion Principle (DIP)

1. element-wise communications
2. rely on interface, not class. Classes changing a lot.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://huang-jason.gitbook.io/complat-software-training-101/iv-3.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
