OO Code Style question
OO Code Style question
- Subject: OO Code Style question
- From: Jamie <email@hidden>
- Date: Thu, 17 Jun 2004 19:17:39 +0100
I am currently learning to program in Cocoa, and one of my first
exercises I am attempting is to convert a program I wrote in
Applescript Studio to objective-c.
The initial flow of the program, is that on opening, it reads an XML
configuration file and then generates various objects based on the data
in the configuration file. I have so far managed to decipher the
NSXMLParser and worked out how to use it, so I now feel confident
grabbing the data from the XML file.
What I want to know is whether it is bad style to delegate the
XMLParsing to each of the objects as they are created in order to
initialise them. I currently have a configController object that
manages the creation of the XMLParser, and each separate configuration
object. The creation of each object is triggered by the recognition of
certain sections of the XML config file. The parser in the
configController works out what type of object it needs to create and
then adds a new one to an array that is an instance variable of the
configContoller class. It then sets the NSXMLParser's delegate to the
new object. The new child object has a section of code to handle being
an NSXMLParser delegate, which tells the object how to initiaite its
instance variables using the XML. Sort of like a backwards
constructor, in that it doesn't run on object creation, but immediately
afterward, and it serves the same purpose. In this way the relevant
sections of XML in the config file get associated with and processed by
the correct type of object.
this is all OK, but I am wondering whether this is the right way to do
things in terms of the MVC paradigm. Is it OK to have the parser code
inside each of the child objects, or would it be better to somehow
leave it all up to the controller to process the XML data and simply
initiate new objects with the resulting data?
This seems more messy in some ways to me, as it may be difficult to get
the XMLParser to differentiate which tags belong to which objects.
Basically, I think I am doing things the right way, but it also seems
to go against MVC to have to much controller type code (IE the
XMLParser filling the object's instance variables) in the configuration
objects.
I hope this makes sense, and that someone can advise me on this point
of style.
Many thanks
Jamie
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.