[Draft]iOS.Architecture.16.Truth-information-flow-and-clear-responsibilities-immutability

來源:互聯網
上載者:User

標籤:model   ash   ios   data   wwdc   logs   objc   john   VID   

Concept: Truth, Information Flow, Clear Responsibilities and Immutability

 

1. Truth

 

1.1 Single Source of Truth

單一的事實/真想來源

Ref[2] Ref[3]

 

"One core principle that is good to keep in mind when modelling various states is to try to stick to

“single source of truth” as much as possible. One easy wayto look at this is that you should never

need to check for multiple conditions to determine what state you are in." Ref[2]

 

1.2 Truth vs 

Ref[1] 

 

 

4. Immutability

google "immutable object in objective-c"

 

4.0 Mutable vs Immutable Object 

 

 

4.1 Why immutable object?

 

Value Object

“In computer science, a value object is a small object that represents a simple entity

whose equality is not based on identity: i.e. two value objects are equal when they

have the same value, not necessarily being the same object.

 

Value objects should be immutable: this is required for the implicit contract that

two value objects created equal, should remain equal. It is also useful for value objects

to be immutable, as client code cannot put the value object in an invalid state or

introduce buggy behaviour after instantiation.” Ref[9]

 

Value Object and Mantle

"For an Objective-C class to be used as a value object, it needs to be immutable,

support value equality, implement proper hashing, and support NSCopying.

Mantle provides the latter three just by subclassing MTLModel. "

 

4.2 Immutability and Builder Pattern

Ref[4] Ref[5] Ref[8]

Too many parameters in initializer method

 

4.3 Builder Pattern in Objective-C and Swift

Objective-C Version

http://www.cnblogs.com/cwgk/p/9013260.html 

Swift Version

Todo

 

4.4 Code Generation

Ref[10] 

 

 

 

 

 

Reference

1. Advanced iOS Application Architecture and Patterns

http://asciiwwdc.com/2014/sessions/229

2. Modelling state in Swift

https://medium.com/@johnsundell/modelling-state-in-swift-3751a4acb8f3

Rules: 

A single source of truth

Making states exclusive

Rendering reactively

Handling state changes

Extracting information

 

3. Single source of truth

https://en.wikipedia.org/wiki/Single_source_of_truth

4. Immutability and Builder Pattern

http://kean.github.io/post/immutability-and-builder-pattern

  • objc.io: Value Objects
  • Wikipedia: Builder Pattern
  • Wikipedia: Immutable Objects
  • Concepts in Objective-C Programming: Object Mutability

5. Value Objects (Read Again)

https://www.objc.io/issues/7-foundation/value-objects/

6. Mutability, aliasing, and the caches you didn‘t know you had

https://garbagecollective.quora.com/Mutability-aliasing-and-the-caches-you-didnt-know-you-had 

7. Boundaries (To Read)

A talk by Gary Bernhardt from SCNA 2012

https://www.destroyallsoftware.com/talks/boundaries

8. Improving Immutable Object Initialization in Objective-C

http://holko.pl/2015/05/12/immutable-object-initialization/

AHKBuilder

9. Simplifying Objective-C Value Objects with Mantle and the Builder Pattern (AAAA+)

https://spin.atomicobject.com/2015/11/02/objective-c-value-objects-mantle/

10. Objective-C Value Objects: Code Generation

https://spin.atomicobject.com/2015/12/16/objective-c-value-objects-code-generation/

11. Building and managing iOS model objects with Remodel

https://code.facebook.com/posts/1154141864616569/building-and-managing-ios-model-objects-with-remodel/

 

[Draft]iOS.Architecture.16.Truth-information-flow-and-clear-responsibilities-immutability

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.