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.

时间: 2024-10-21 09:48:44

IOS - design patterns - object template(swift)的相关文章

Learning JavaScript Design Patterns -- A book by Addy Osmani

Learning JavaScript Design Patterns A book by Addy Osmani Volume 1.6.2 Tweet Copyright © Addy Osmani 2015. Learning JavaScript Design Patterns is released under a Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 unported license. It

Learning JavaScript Design Patterns The Module Pattern

The Module Pattern Modules Modules are an integral piece of any robust application's architecture and typically help in keeping the units of code for a project both cleanly separated and organized. In JavaScript, there are several options for impleme

Design Patterns Example Code (in C++)

Overview Design patterns are ways to reuse design solutions that other software developers have created for common and recurring problems. The design patterns on this page are from the book Design Patterns, Elements of Reusable Object-Oriented Softwa

23中设计模式(Design Patterns)转载

设计模式(Design Patterns) ——可复用面向对象软件的基础 设计模式(Design pattern)是一套被反复使用.多数人知晓的.经过分类编目的.代码设计经验的总结.使用设计模式是为了可重用代码.让代码更容易被他人理解.保证代码可靠性. 毫无疑问,设计模式于己于他人于系统都是多赢的,设计模式使代码编制真正工程化,设计模式是软件工程的基石,如同大厦的一块块砖石一样.项目中合理的运用设计模式可以完美的解决很多问题,每种模式在现在中都有相应的原理来与之对应,每一个模式描述了一个在我们周

IOS开发—Using UIGestureRecognizer with Swift Tutoria

Update note: This tutorial was fully updated for iOS 8 and Swift by Caroline Begbie. Original post by Ray Wenderlich. Update 12/10/14: Updated for Xcode 6.1.1. If you need to detect gestures in your app, such as taps, pinches, pans, or rotations, it'

设计模式(Design Patterns)(转)

设计模式(Design Patterns) ——可复用面向对象软件的基础 设计模式(Design pattern)是一套被反复使用.多数人知晓的.经过分类编目的.代码设计经验的总结.使用设计模式是为了可重用代码.让代码更容易被他人理解.保证代 码可靠性. 毫无疑问,设计模式于己于他人于系统都是多赢的,设计模式使代码编制真正工程化,设计模式是软件工程的基石,如同大厦的一块块砖石一样.项目中合理的运用 设计模式可以完美的解决很多问题,每种模式在现在中都有相应的原理来与之对应,每一个模式描述了一个在我

Learning JavaScript Design Patterns The Observer Pattern

The Observer Pattern The Observer is a design pattern where an object (known as a subject) maintains a list of objects depending on it (observers), automatically notifying them of any changes to state. When a subject needs to notify observers about s

The iOS Design Cheat Sheet 界面设计速参

http://ivomynttinen.com/blog/the-ios-7-design-cheat-sheet/ With the release of iOS 7, app designers and developers will need to adjust their visual language to match the new "flat" design of iOS. In addition to the grid system, the dimensions of

Design Patterns 乌蒙山连着山外山---单件模式singleton pattern

1 //包含单件实例的类Singleton 2 public class Singleton 3 { 4 //声明用于存储单件实例的变量instance 5 private static Singleton instance; 6 //定义用于标识同步线程的对象locker 7 private static Object locker = new Object(); 8 //私有的构造函数Singleton 9 private Singleton() { } 10 //公共访问的返回单件实例的函