1、使用场景
原型模式通俗来讲就是拷贝模式,通过拷贝操作来生成一个对象的副本,从而快速生成对象。在iOS中原型模式应用的实例就是NSCopying和NSMutableCopying拷贝协议了。调用一个对象的copy(mutableCopy)方法,该对象必须得实现NSCopying(NSMutableCopying)协议。
2、实现举例
- (id)copyWithZone:(NSZone *)zone
{
ThroughTrainLineSearchRequestData* copy = [[ThroughTrainLineSearchRequestData alloc] init];
copy.placeData = [self.placeData copy];
copy.from_site_id = [self.from_site_id copy];
copy.to_site_id = [self.to_site_id copy];
copy.date = [self.date copy];
copy.time_type = [self.time_type copy];
copy.page = [self.page copy];
copy.recommend_id = [self.recommend_id copy];
return copy;
}