iv - 3
Clean Code
software = build a house
basic = building plan.
build different purpose: apartment, hotel, business, etc.
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
restricting direct access to some
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
one module one role
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)
separate data & logic
A rely on B, and B rely on C. A and B will be changed when changing C
Dependency Inversion Principle (DIP)
element-wise communications
rely on interface, not class. Classes changing a lot.
Last updated
Was this helpful?