Frage

So, I'm rewriting an old application built by another developer - who is no longer part of our team.

What I have noticed is that in the AppDelegate there are the standard methods in there. On top of that there is also about another 30 other methods in there - from setting UI stuff to checking is things like T&Cs have been accepted - to showing items in a cart and even perfuming logouts and logins etc.

Now I am still new to iOS dev and I have been reading that abusing the app delegate isn't a great idea. Would this be considered as abuse?

Through out the application - the developer uses:

MyAppDelegate *appDelegate = (MyAppDelegate*)[MyAppDelegate sharedAppDelegate];

Which I think is probably not the best approach?

If this is abusing the AppDelegate - how does one solve it - without using singletons?

I'm thinking of creating a new class and grouping the methods into relevance? So anything to do with setting items / checking etc - into one class. Then UI stuff could probably stay in the app delegate?

I think breaking this up will help with decoupling and dependancies. But is it the right way if most of the stuff in the App delegate is used to "Do" stuff and not store?

War es hilfreich?

Lösung

I'm not sure about abusing part of the AppDelegate Class but in Programming prospective you should separate code into meaning full classes! Then it becomes easier to Manage.

Back to your problem! You can always create Singleton class also you can create category class for AppDelegate class So in a way you are separating the code.. Meaning if you have login/logout methods in delegate you can create Category called +UserManagement or Something and put all your code there! Also you can create AppUser Singleton class and put all the user management stuff there!

Andere Tipps

I would consider using AppDelegate as smelly code. Singletons are better but take in mind that they are hard to unit test.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top