I am creating a Framework in objective C , which has multiple features, where all the features are need to be initialized while instatiating the library instance, where I am also giving flexibility of providing alternate implementation to any of the feature, to acheive this I am using builder pattern as follow, My question is, Which better Design pattern suits here? Or how Can I improve performace/Memory usage, Please suggest me some pattern for this problem
-(instancetype)initWithBuilder:(LibraryBuilder *)builder {
self = [super init];
if (self) {
// allocate feature1 instance
if (builder.feature1)
self.feature1 = builder.feature1;
else
self.feature1 = [[InterfaceA alloc] initWithLib:self];
// allocate feature2 instance
if (builder.feature2)
self.feature2 = builder.feature2;
else
self.feature2 = [[InterfaceB alloc] init];
// allocate App Configuration instance
if (builder.feature3)
self.feature3 = builder.feature3;
else
self.feature3 = [[InterfaceC alloc] init];
// allocate feature4 instance
if (builder.feature4)
self.feature4 = builder.feature4;
else
self.feature4 = [[InterfaceD alloc] init];
// allocate feature5 instance
if (builder.feature5)
self.feature5 = builder.feature5;
else
self.feature5 = [[InterfaceE alloc] init];
// allocate feature6 instance
if (builder.feature6)
self.feature6 = builder.feature6;
else
self.feature6 = [[InterfaceF alloc] init];
// allocate feature7 instance
if (builder.feature7)
self.feature7 = builder.feature7;
else
self.feature7 = [[InterfaceG alloc] init];
// allocate feature8 instance
if (builder.feature8)
self.feature8 = builder.feature8;
else
self.feature8 = [[InterfaceH alloc] init];
return self;
}
Aucun commentaire:
Enregistrer un commentaire