objective c – What is the convention used when abstracting iPhone/iPad code into a Universal Binary? – Education Career Blog

So I am currently working on a universal binary for an app that is to be ran on iPad and iPhone. The differences are basically only UI changes.

So, with that in mind, I have a class called ConfigurationController that is of type UIViewController. I then sub class ConfigurationController into iPadConfigurationController and iPhoneConfigurationController.

Now, lots of the code is common, so I abstracted it out to the ConfigurationController. However, there are a few functions in which the changes result in 1 line code differences. Im currently in a debate with other developers about what to do with this code.

There seem to be two paths:
1: push the methods into the ConfigurationController super class, then use macros to determine if the app is being run on an iPad or an iPhone. Then call which ever code needs to be called based on that.

2: keep the methods in the subclasses (iPadConfigurationController and iPhoneConfigurationController) and keep the 1 line changes. This results in about 300 lines of code being duplicated. However, this leaves a path for the future, as in if there is a change now, there can be change after further development. In which case, I would already have the functions in the subclasses.

Which would be more beneficial and have less overhead?

,

Refactor the 1-line differences into small helper functions, declared in the base class, but implemented in the derived classes (I’m more a C++ guy, so I hope the terminology makes sense).

Leave a Comment