Iphone -- init method of an abstract class

Posted by William Jockusch on Stack Overflow See other posts from Stack Overflow or by William Jockusch
Published on 2010-03-29T22:39:30Z Indexed on 2010/03/29 22:43 UTC
Read the original article Hit count: 322

Filed under:
|

I want to create classes Car, Vehicle, and Airplane with the following properties:

  • Car and Airplane are both subclasses of Vehicle.
  • Car and Airplane both have an initWithString method.
  • The acceptable input strings for Car's and Airplane's initWithString methods do not overlap.
  • Vehicle is "almost abstract", in the sense that any initialized instance should be either a Car or an Airplane.
  • It is possible to pass a string into Vehicle and get back an instance of Car, an instance of Airplane, or nil, depending on the input string.

Any particular design pattern I should prefer? In particular for Vehicle's initWithString and/or newVehicleWithString methods.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about abstract-class