Note that there are some explanatory texts on larger screens.

plurals
  1. PODe-coupling Model and Separating Public/Private Methods in Objective-C (Protocols vs Public/Private Headers)
    primarykey
    data
    text
    <p>I'm currently building a game in Objective-C (for iPhone).</p> <p>For this I'm slightly breaking MVC for performance/complexity reasons and giving the view (renderer) a direct reference to the model. This is because it's supposed to run at 60fps and is constantly updating itself based on the model's state.</p> <p>I have properties that are read-write in my model's header files, due to other classes in my model needing to access and set those. But they should act as readonly for my view. So I have the issue of needing to separate public/private methods.</p> <p>I think a typical approach to this is to have a normal "X.h" header, which the view will import and a separate "X_private.h" for the other model classes to use internally.</p> <p>A Java developer friend of mine suggested a different approach using protocols.</p> <p>He suggested creating protocols of NSObject like "IX.h", which would contain the public methods the view references. Then simply having the class (X.h/X.m) setup with private (in terms of the whole model) methods on it's header and having that class implement the protocol.</p> <p>This seems pretty cool as it adds a further layer of abstraction. Now if I decide to change the underlying model classes and how they work, I can do so as long as they still implement the public protocol. The view doesn't even know what classes the model really uses underneath.</p> <p>I don't see any obvious downside to this approach, but it's not something I've done before in Objective-C.</p> <p>Is this a good approach or am I missing something?</p> <p>Are there are other good approaches to this problem?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload