objective-c编程概念(二)类群

Class Clusters

Class clusters are a design pattern that the Foundation framework makes extensive use of. Class clusters group a number of private concrete subclasses under a public abstract superclass. The grouping of classes in this way simplifies the publicly visible architecture of an object-oriented framework without reducing its functional richness. Class clusters are based on the Abstract Factory design pattern.

类群

类群是一种设计模式,在Foundation框架中大量使用. 类群在一个公共的抽象的父类下,聚集了一组私有的具体的子类。用这种方式组合类能够简化一个面向对象框架的公共可见架构,同时还不会降低功能的丰富性。类群是基于抽象工厂方法这一设计模式。

Without Class Clusters: Simple Concept but Complex Interface

To illustrate the class cluster architecture and its benefits, consider the problem of constructing a class hierarchy that defines objects to store numbers of different types (charintfloatdouble). Because numbers of different types have many features in common (they can be converted from one type to another and can be represented as strings, for example), they could be represented by a single class. However, their storage requirements differ, so it’s inefficient to represent them all by the same class. Taking this fact into consideration, one could design the class architecture depicted in Figure 1-1 to solve the problem.

没有类群: 简单的概念,复杂的接口

为了说明类群架构和它的好处, 考虑这样一个问题,建立一个类层级,用它来定义对象,对象可以存储不同类型的数(char, int, float, double)。因为不同类型的数有很多功能是一致的(例如,它们可以从一种类型转换到另一种,也可以被表示为字符串), 所以它们可以被表示为一个独立的类。 然后,它们的存储需求是不同的,所以用同样的类去表示它们是很低效的。考虑到这样一个事实,我们可以设计一个类架构,如图1-1来解决这个问题。



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值