IOS - design patterns - object template(swift)

a.concepts explain:

object: which is created from struct or class template 

instance: which is just used to declare a reference of class or struct it was created from, and it's the same meaning as object

b.purpose:

the purpose to use class or struct as the template of objects is to prevent tightly coupled components, which means to make the different components in the same project to have lower relationship with each other,further more when we change one component in the project we don't have to change the other component very much and maybe even rewrite the other components.

To make this much more clear, when we access one object from another one, we only can see the name of properties and methods(include return value), we have no idea about the implementation. In swift we have access control, using public, private or internal as the mark. internal: the default value without specifying the mark. and can be accessed in the same project.

private: specify the private mark before the property and methods.only can be accessed from the same file

public: specify the public mark before the property and methods. usually used when develop framework and can be accessed outside of the project.

using access control we can only expose the API we want the other objects to use, and hide the properties or methods we dont want to, which can lead to loosely coupling.

for example, we can use computed properties to be the API for other objects, and we can use the set{}or get{}to interact with private value and add more spedified logic.

Sorry guys i'm using a chinese blog website, so i have no idea if there is a blog i can use in english, please leave any comments below and the related chinese word is "评论",thank you so much for your reading, and if you have any suggestions please leave it below. 

posted @ 2015-12-03 18:05  李扬  阅读(158)  评论(0编辑  收藏  举报