IOS - design patterns - object template(swift)

來源:互聯網
上載者:User

標籤:

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. 

IOS - design patterns - object template(swift)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.