首页 > 数据库技术 > 详细

二十二、访问控制 Access Control

时间:2015-02-09 12:41:24      阅读:292      评论:0      收藏:0      [点我收藏+]

1. 概述

访问控制用于限制其他文件和模块访问你的代码中的某些部分,让你可以隐藏你的代码的具体实现,同时让你可以指定一些可以被其他文件和模块访问的借口。

 

2. Modules and Source Files

Swift的访问控制基于模块和源文件。

A module is a single unit of code distribution—a framework or application that is built and shipped as a single unit and that can be imported by another module with Swift’s import keyword.

A source file is a single Swift source code file within a module (in effect, a single file within an app or framework).

 

3. 访问等级 Access Levels

实体 entities:本文所指的实体指访问控制相关的 properties, types, functions and so on

Swift提供了三种不同的访问等级,访问等级与实体所在的源文件有关,也与源文件所属的模块有关。

1)Public 可以被其他任何地方访问。比如一个 framework 的public interface。

2)Internal 允许实体可以被模块(定义实体的模块)中的任意源文件中访问,但是不能被模块外的文件访问。比如你定义一个 app 或 framework 的 internal structure。

3)Private 限制实体只能在定义自己的源文件中使用。可以使用 Private 隐藏一些功能的实现细节。

public 有最高的访问等级,highest (least restrictive)。

private 有最低的访问等级,lowest (or most restrictive)。

 

4. 访问等级的指导原则 Guiding Principle of Access Levels

 

二十二、访问控制 Access Control

原文:http://www.cnblogs.com/actionke/p/4281033.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!