java - Replace constructor with factory method -


In Java, a factory manufacturer can be defined in an abstract superclass:

  Make a Public Static GuardianTilfrom Type (Int Type) {Switch (Type) {Case 0: Return New Child 1 (); Case 1: New hair 2 () returned; Default: throw a new exception (); }}  

But, in Objective-C, I'm not getting any known class method for 'Selector' for "all code" case1 :

  #import "Child1.h" #import "Child2.h" @implementationParent + (id) createChildFromType: type {switch (type) {case 0: return [[Child1 Alloc] init]; Case 1: Return [[Child2 alloc] init]; Default: @ throw [NSE option with name exception: NSInternalInconsistencyException Reason: @ "Invalid subclass type." UserInfo: zero]; }} - (zero) someAbstractMethod {@throw [NSException exception: with name: NSInternalInconsistencyException reason: [NSString stringWithFormat: @ "You must override% @ in a subclass.", NSStringFromSelector (_cmd)] userInfo: zero]; } @end  

Both Child1.h and Child2.h is #import "Parent.h" Because I want to call someAbstractMethod , before I'm calling the sub-class:

  - (zero) someVoodooMethod :( int) type {Parents * Children = [Generate Type Generator Type: Type]; [Baby someAbstractMethod]; }  

I have a hip that is due to the unimplemented #import "Parent.h" in the @implementation parent , but I have not thought of a way around it, any suggestions?

Edit:

I think the code should be included for Child1.h :

#import "Parent.h" @ Interface child 1: parent @ and

and Child2.h

  #import "parent.h" @interface Child 2: Generator @end  

You need forwarding for forwarding the parents of the children forward.

Here is a link to the next declaration in obj-c:

just add

  @class parent;  

In child1.h, child2.h.

In child1.m, child2.m you can include parents.


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -