views:

45

answers:

1

Hi guys,

i' a new iphone developer coming from flash stuff.

let me tell you about my problem: i'm doing a puzzle game and have a tab bar controller with 4 tabs. i use 1 tab for sign up and other for login, they works different but uses a lot of the same code (displaying images, playing sounds, settings stuff, audio things, animations things, and so on).

the point is that the 2 views have almost the same ui elements, i.e. the differences about them are 2 labels.

when i was using flash it was easy, i reused the elements: if i was in the login window i just hid the 2 additional sign up labels. 1 class controlled everything. it was easy and fast.

here i have created 2 views: sign up and login (one for each one)
1 class: "SingUpLoginViewController.m" controls everything (please note: 1 class, but 2 instances)

Question
it works but my concern is if it's the correct design? other way could be separating "SingUpLoginViewController.m" in "SingUpViewController.m" and "LoginViewController.m".
and other way could be sharing the same instance.

thanks for your help

A: 

Nothing wrong with that. It's even good to do something like that to avoid code duplication.

An alternative would be to create a base class that implements the logic common to both views and then create two subclasses, one for each views, that implements the things that differentiates it from the other view.

Both ways are fine. The base class way is probably more "clean" from a theoretic point of view, but if the differences aren't very big your pragmatic one-class-for-both-views isn't bad either.

DarkDust
ok, thanks, i think the base class idea sounds gound. The diferences are like: "signUpDidEnd", "loginDidEnd" and so on. one more time, thanks for your reply
jhon