Object Oriented Programming
☑️ Sequential Programming
- program runs by order
- unstructued programming
- 👎🏻 if need code from before, use goto
- need to pay attention to flow(in what order will this code be run), instead of code developemnt
☑️ Procedural Programming
- structured programming
- repreated codes are made into method(procedure)
- procedure: method that does not return
- 👎🏻 too abstract
✅ Obejct Oriented Programming
- 현실 세계를 프로그래밍 세계로 옮겨와 현실 세계의 사물들을 객체로 생각
- 객체의 특징, 기능을 뽑아 프로그래밍
- class has field, getter, setter
- to manage an object’s field and method toegether
What are the benefits of OOP?
👍🏻 code reuseablility
👍🏻 can adapt code for several purposes
👍🏻 Abstraction
1
2
3
- fish, cat, dog all fit in animal
- animal is abstraction
- get all common characteristics, into one object
why use abstraction?
if tiger is added, need to develop just the new part for animal istead of developing all over again .
👍🏻 Encapsulation
if alternation happens, minimize impact on other codes
minimize coupling
minimize dependencies of independent objects
- use private field
👍🏻 Inheritence
another type of encapulsation capsulize child class from public
👍🏻 Polymorphism
child class can override parent class method, and use it as it wants
✅ SOLID
OOP 설계 원칙
how to program object oriented
1. SRP
Single Responsibility
class should have one responsibility
- not to affect other codes
2. OCP
Open Closed Policy
- open for expansion, closed for update
- can update or change function, however do not change the code.
3. LSP
Liskov Substitution Principle
- object of a superclass should be replaceable with an object of a subclass without affecting the correctness or consistency of the program’s behavior
4. ISP
Interface Segregation Principle
- interface should be seperate
5. DIP
Dependency Inversion Principle
- should depend on abstraction
- 추상화(인터페이스)에 의존해야 하며, 구체화(구현된 클래스)에 의존해서는 안된다.
This post is licensed under CC BY 4.0 by the author.