Ios-design patterns-object Template (Swift)

Source: Internet
Author: 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's created from, and it's the same meaning as O Bject

B.purpose:

The purpose to use class or struct as the template of objects are to prevent tightly coupled components, which means to mak E the different the same project to a lower relationship with each other,further Component in the project we don ' t has to change the other component very much and maybe even rewrite the other components .

Much more clear, when we access one object from another one, we only can see the name of the properties and Metho DS (include return value), we have no idea about the implementation. In Swift we had 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 is accessed from the same file

Public:specify the public mark before the property and methods. Usually used when develop framework and can is 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 do NT want to, which can leads to loosely coupling.

For example, we can use computed properties to being the API for other objects, and we can use the Set{}or get{}to interact W ith private value and add more spedified logic.

Sorry guys i ' m using a Chinese blog website, so I had no idea if there was a blog I can use in 中文版, please leave any C Omments below and the related Chinese word is "review", thank you so much for your reading, and if you had any suggestions ple ASE Leave it below.

Ios-design patterns-object Template (Swift)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.