Notice
Recent Posts
Recent Comments
Link
관리 메뉴

김종권의 iOS 앱 개발 알아가기

[Clean Architecture] 0. 코드로 알아보는 SOLID - 클래스 다이어그램 필수 표현 본문

Clean Architecture/Clean Architecture 코드

[Clean Architecture] 0. 코드로 알아보는 SOLID - 클래스 다이어그램 필수 표현

jake-kim 2021. 9. 17. 01:22

0. 코드로 알아보는 SOLID - 클래스 다이어그램 필수 표현

1. 코드로 알아보는 SOLID - SRP(Single Responsibility Principle) 단일 책임 원칙

2. 코드로 알아보는 SOLID - OCP(Open Close Principle) 개방 폐쇄 원칙

3. 코드로 알아보는 SOLID - LSP(Liskov Substitution Principle) 리스코프 치환 원칙

4. 코드로 알아보는 SOLID - ISP(Interface Segregation Principle) 인터페이스 분리 원칙

5. 코드로 알아보는 SOLID - DIP(Dependency Inversion Principle, testable) 의존성 역전 원칙

6. 코드로 알아보는 SOLID - Coordinator 패턴 화면전환

7. 코드로 알아보는 SOLID - Network, REST (URLSession, URLRequest, URLSessionDataTask)

8. 코드로 알아보는 SOLID - 캐싱 Disk Cache (UserDefeaults, CoreData)

사용관계 vs 상속(구현)관계

  • 화살표와 닫힌 화살표로 구분

  • 사용관계(의존관계)의 개념: A클래스에서 B의 흔적이 하나라도 있으면 사용관계
    • A에서 B의 객체를 property로 가지고 있는 것
    • A에서 B의 객체를 생성하는 부분이 존재하는 것
    • A에서 메소드나 초기화에서 b를 매개변수로 받는 것
    • A에서 B의 property에 접근하는 것
    • A에서 B의 method에 접근하는 것
protocol C {}

class A: C {

    // 사용1. B의 객체를 property로 가지고 있는 것
    let b: B

    // 사용2. B객체 생성
    func makeB() -> B {
        return B()
    }

    // 사용3. A클래스인데 매개변수로 b를 받는 것
    init(b: B) {
        self.b = b
    }

    func printB() {
        // 사용4. B의 property에 접근
        print(b.className)
    }

    func printBMethod() {
        // 사용5. B의 메소드에 접근
        print(b.printClassName())
    }
}

class B {
    var className = "i'm B"

    func printClassName() {
        print(className)
    }
}

DS, I 기호

  • DS: Data Structure
    • I: Interface (스위프트에서의 protocol)

Comments