[Draft]iOS.Architecture.16.Truth-information-flow-and-clear-responsibilities-immutability
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
a “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]
2. Information Flow (Data Flow)
3. Clear Responsibilities
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 (DSL, ruby)
Ref[10]
4.5 Code Generation (remodel)
Ref[11] Ref[12]
Remodel Plugin
https://github.com/facebook/remodel/blob/master/PLUGINS.md
4.6 Code Generation (plank)
Ref[13]
4.7 Consistency
Ref[14]
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/
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/
12. remodel
https://github.com/facebook/remodel
Remodel is a tool that helps iOS and OS X developers avoid repetitive code by generating Objective-C
models that support coding, value comparison, and immutability.
13. plank
A tool for generating immutable model objects https://pinterest.github.io/plank/
https://github.com/pinterest/plank/
https://github.com/plivesey/ConsistencyManager-iOS
15. iOS响应式架构
http://blog.mrriddler.com/2017/06/28/iOS响应式架构/
16. Single Source of Truth Principal in Software Development (Android)
https://www.youtube.com/watch?v=Ex9IT1bq0PQ
https://codingwithmitch.com/courses/android-local-database-cache-rest-api/demo/
In this course you'll learn how to build a local database cache with SQLite and Room.
The cache retrieves data from a REST API using Retrofit2. Architecture is MVVM.
17. Difference between Single Source Of Truth and Single Responsibility Principle?
https://softwareengineering.stackexchange.com/questions/284874/difference-between-single-source-of-truth-and-single-responsibility-principle
18. Understanding One Source of Truth for Analytics
https://blogs.workday.com/understanding-one-source-truth-analytics/
19. The Single Source of Truth
https://blog.buckets.co/the-single-source-of-truth-430b61d10e19
20. Why Single Source of Truth Data Systems Kill Team Collaboration
https://unito.io/blog/a-single-source-of-truth-data-system-kills-team-collaboration-heres-why/
21. Single Source of Truth
https://www.dragon1.com/concepts/single-source-of-truth
22. Single Source of Truth…and Why it Matters
https://medium.com/@elisavaccaro/single-source-of-truth-and-why-it-matters-a68e28b8c175
23. 应用架构指南
https://developer.android.com/jetpack/docs/guide
[Draft]iOS.Architecture.16.Truth-information-flow-and-clear-responsibilities-immutability的更多相关文章
- Risk Adaptive Information Flow Based Access Control
Systems and methods are provided to manage risk associated with access to information within a given ...
- iOS Architecture Patterns
By Bohdan Orlov on 21 Mar 2016 - 0 Comments iOS FYI: Slides from my presentation at NSLondon are ava ...
- iOS根据16进制的色号来设置颜色,适合封装工具类
iOS中有时候UI给的一个色号就像 #54e1b7 这个,而我们一般设置颜色都是根据RBG来设置的,所以这里需要把这个16进制的色号转为RGB值,这里我们就使用一下的方法来调用设置颜色. + (UIC ...
- iOS Architecture和Valid architectures
目前ios的指令集有以下几种: 1,armv6,支持的机器iPhone,iPhone2,iPhone3G及对应的iTouch 2,armv7,支持的机器iPhone4,iPhone4S 3,armv7 ...
- iOS Architecture
目前ios的指令集有以下几种: armv6 iPhone iPhone2 iPhone3G 第一代和第二代iPod Touch armv7 iPhone4 iPhone4S armv7s iPhone ...
- [iOS]把16进制(#871f78)颜色转换UIColor
// // ViewController.m // text // // Created by 李东旭 on 16/1/22. // Copyright © 2016年 李东旭. All rights ...
- 【转】iOS中16进制转10进制
原文网址:http://www.voidcn.com/blog/u012198553/article/p-4976772.html /// 将十六进制的字符串转化为NSData - (NSData ) ...
- iOS开发-16进制颜色转换
项目中经常会用到颜色转换,有的是通过十六进制转成数字转颜色,想简单的点直接通过字符串转一下,简单扩展了一下分类UIColor,代码如下: +(UIColor *)colorWithHex:(NSStr ...
- IOS 颜色 16进制 转换
#define RGB(r,g,b) ([UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1]) #define HEXTO ...
随机推荐
- java9 Local-variable type inference
var ls = Arrays.asList("1","2"); System.out.println(ls);
- 003.[python学习] 简单抓取豆瓣网电影信息程序
声明:本程序仅用于学习爬网页数据,不可用于其它用途. 本程序仍有很多不足之处,请读者不吝赐教. 依赖:本程序依赖BeautifulSoup4和lxml,如需正确运行,请先安装.下面是代码: #!/us ...
- 团队作业-Week9-软件项目的风险
一.软件项目中的风险 软件项目的风险无非体现在以下四个方面:需求.技术.成本和进度.IT项目开发中常见的风险有如下几类: (1)需求风险 ①需求已经成为项目基准,但需求还在继续变化: ②需求定义欠佳, ...
- Hive:map字段存储和取用 ( str_to_map函数 )
str_to_map(字符串参数, 分隔符1, 分隔符2) 使用两个分隔符将文本拆分为键值对. 分隔符1将文本分成K-V对,分隔符2分割每个K-V对.对于分隔符1默认分隔符是 ',',对于分隔符2默认 ...
- FPGA——按键(二)
直接上源码: module key_led( input sys_clk , //50Mhz系统时钟 input sys_rst_n, //系统复位,低有效 :] key, //按键输入信号 :] l ...
- 关于C#关闭窗体后,依旧有后台进程在运行的解决方法
http://www.cnblogs.com/HappyEDay/p/5713707.html 这里粘贴原文权当备份了. C#中WinForm程序退出方法技巧总结 一.关闭窗体 在c#中退出WinFo ...
- python的车牌号的检测
自己总结一下,从网上找到的关于车牌号的识别的一些博文.https://www.jianshu.com/p/fcfbd3131b84 https://www.cnblogs.com/do-hardwor ...
- PHP拦截器之__set()与__get()的理解与使用方法
“一般来说,总是把类的属性定义为private,这更符合现实的逻辑. 但是,对属性的读取和赋值操作是非常频繁的,因此在PHP5中,预定义了两个函数“__get()”和“__set()”来获取和赋值 ...
- php 配置xdebug
https://blog.csdn.net/Alan8865/article/details/81331252
- C语言的三目运算符(x=a?b:c):条件运算符
三目运算符使用是为了有条件判断的选择赋值 x = a ? b : c 先计算 a表达式 是否为真.若为真,x 的值便是 b表达式的值,否则 x的值便是 c表达式的值. 条件运算符是右结合的. 如:a ...