수직 확장과 수평 확장에 대한 생각 === ###### tags: `opinion` [TOC] ### 상위 클래스 상속을 활용한 수직 확장 vs 프로토콜을 활용한 수평 확장 뷰 내부 구성 요소가 많음에 따라 해당 뷰들을 나누는 노력을 했음. 코드를 활용해 뷰를 작성하는 과정에서 일관된 흐름을 가져가기 위한 시도를 함. 의미적으로도 일관된 면에서도 프로토콜의 활용이 더 의미가 있지 않을까 생각했다. ```swift= class BaseView: UIView { override init(frame: CGRect) { super.init(frame: frame) applyViewSettings() } @available(*, unavailable) required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } } extension BaseView { func buildHierarchy() { } func setupConstraints() { } func viewConfigure() { } func applyViewSettings() { buildHierarchy() setupConstraints() viewConfigure() } } ``` ```swift= protocol ViewConfiguration { func buildHierarchy() { } func setupConstraints() { } func viewConfigure() { } } extenion ViewConfiguration { func applyViewSettings() { buildHierarchy() setupConstraints() viewConfigure() } } class CustomView: UIView { override init(frame: CGRect) { super.init(frame: frame) applyViewSettings() } @available(*, unavailable) required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } } extension CustomView: ViewConfiguration { func buildHierarchy() { } func setupConstraints() { } func viewConfigure() { } } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up