Is there an advantage to dividing iPhone and iPad classes on a universal app?

I have a Universal app (for iPhone and iPad).

Are there any advantages to separating the iPad from the iPhone classes in the folder structure?

Here is an example of what I mean:

- MyApp - Resources - Classes - iPad - SomeUniqueClassOnIPad.h - SomeUniqueClassOnIPad.m - iPhone - SomeUniqueClassOnIPhone.h - SomeUniqueClassOnIPhone.m - SomeUniversalClass.h - SomeUniversalClass.m 

Is this common in objective-c projects?

+6
source share
2 answers

One of the rules in coding should never have duplicate code, so if your views do different things or if the data is processed differently depending on whether it has an iPad or iPhone (for example, different data sources?), Then this must be in different classes, if not .. then no. Use the same class.

One thing that is common and that you could implement in such a case is a kind of helper, a delegate class, if you want, that handles all the common methods and actions that happen in your code.

Golden rule: write as little code as possible! Less code == more maintainable and of higher quality. Therefore, write as little code as possible, but do not affect your requirements. Also, split the code to make it an easier (unitary) test and therefore easier to reuse.

I hope that answered your question.

Update
I know there is terminology for this, just think about it. The presence of duplicate code is called a โ€œDRY violationโ€. DRY stands for "Do not Repeat Yourself," which is a software development principle designed to reduce the repetition of all kinds of information, especially useful in multi-level architectures.
More info: DRY on Wikipedia

+9
source

For me, it depends on the commonality between the iPhone and iPad. If there are separate xib files, but both contain the same elements, it is easy to decide to use the same class.

If iPhone and iPad xib files have unique elements, class separation might be better.

Another option is to create a base class that the iPhone and iPad classes share for cases when you want to separate them. The base class will contain code that is common between them, for example, initiating data requests or a common user view.

+1
source

Source: https://habr.com/ru/post/914535/


All Articles