4.0 KiB
title, created, updated, type, tags, external
| title | created | updated | type | tags | external | ||
|---|---|---|---|---|---|---|---|
| Software Design | 2020-04-08 | 2020-04-08 | summary |
|
https://github.com/wahyd4/knowledge/blob/master/categories/software-design.md |
Refactoring
-
when to refactor
- long method
- too many parameters
- duplicated code
- large class
- too many if else or case when
- temporary variable
- coupling
OOP
Object-oriented programming (or OOP) is a paradigm or pattern of programming whereby the solution to a programming problem is modelled as a collection of collaborating objects. Objects collaborate by sending messages to each other. It is most suitable for managing large, complex problems.
The four principles of object-oriented programming are
-
encapsulationObject encapsulates data and the functions that operate on that data -
abstractionYou don't need to what happened under the hood, just know how to use the public methods is enough. -
inheritanceSharing common behaviours -
polymorphismPolymorphism means that when an object receives a message, the correct method is called, based on the object’s class. That method may belong to the parent, or it may be one that is customized for this class. -
Polymorphism
- Code to interface, not an implementation
-
Composition over inheritance
- objects have high cohesion and low coupling with other objects
-
Duck typing
-
SOLID
- Single responsibility
- Open/Closed
- Liskov substitution
- Interface segregation
- Dependency inversion
Functional programming
-
pure functions
- giving a same input, always return same output
- produce no side effects
- reply on no external mutable state
-
function composition
-
avoid share state
-
avoid mutating state
-
avoid side effects
Serverless
-
Lambda
- A lambda is just an anonymous function - a function defined with no name
Closure
- a function value that references variables from outside its body
- In Javascript, not all anonymous function are lamdba, and vise verse
Event Sourcing
Kafka
Apache Kafka is a distributed streaming platform
There are 4 core APIs in kafka:
- Producer API
- Consumer API
- Streams API
- Connector API
Command Query Responsibility Segregation (CQRS)
Every changes you made to the system is a event, events are been persisted and can be replayed to generate the materialized view.
In his book "Object Oriented Software Construction," Betrand Meyer introduced the term "Command Query Separation" to describe the principle that an object's methods should be either commands or queries. A query returns data and does not alter the state of the object; a command changes the state of an object but does not return any data. The benefit is that you have a better understanding what does, and what does not, change the state in your system.
More:
UML
- many_to_many
- one to many
One UML example
Java Design pattern
How to do Data Migration
-
Add logic to support both new and old data structures
-
Add Logic should read both old and new data but only write data to new schema/structure
-
Then migrate the old data schema to new one
-
Last, delete the logic which handle the old data schema.
Some tips
-
concurrency vs parallelism
- parallelism
- doing a lot of things at once
- about exection
- concurrency
- dealing with lots of things at once
- about structure
- parallelism


