在通用应用程序上分离iPhone和iPad类有什么优势吗? [英] Is there any advantage on separating iPhone and iPad classes on a Universal app?

查看:130
本文介绍了在通用应用程序上分离iPhone和iPad类有什么优势吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个通用(对于iPhone和iPad)应用程序。



在文件夹结构中将iPad与iPhone类分开有什么优势吗? p>

以下是我的意思示例:

   -  MyApp 
- 资源
- 类
- iPad
- SomeUniqueClassOnIPad.h
- SomeUniqueClassOnIPad.m
- iPhone
- SomeUniqueClassOnIPhone.h
- SomeUniqueClassOnIPhone.m
- SomeUniversalClass.h
- SomeUniversalClass.m

在objective-c项目中的共同点?

解决方案

编码中的一个规则是永远不会有重复的代码,正在做不同的事情,或者如果数据应该处理不同取决于它的iPad或iPhone(例如不同的数据源?),它应该绝对是在不同的类,如果没有..然后没有。使用同一个类。



在这种情况下,你可以实现的一件事是一种帮助器,一个委托类,如果你愿意,在您的代码中发生的所有常见方法和操作。



黄金规则:尽可能编写尽可能少的代码!更少的代码==更可维护,具有更高的质量。所以写尽可能少的代码,但不影响你的要求。
此外,分割代码使其更容易(单位)测试,从而更容易重用。



我希望回答你的问题。 >

更新 \\ $ b我知道这里有一个术语,只是可以想到它。具有重复的代码被称为DRY违反。 DRY代表Do not Repeat Yourself,这是一种旨在减少各种信息重复的软件开发原则,尤其适用于多层体系结构。

详细信息: DRY维基百科


I have a Universal (for both iPhone and iPad) application.

Are there any advantages on 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 that common in objective-c projects?

解决方案

One of the rules within coding is never to have duplicate code, so if your views are doing different things or if data should be handled differently depending on if its an iPad or iPhone (e.g. different data sources?) it should definitely be in different classes, if not.. then no. Use one and the same class.

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

Golden rule: Write as little code as possible! Less code == more maintainable and has a higher quality. So write as little code as possible yet without affecting your requirements. Also, split up code so its easier to (unit)test and thereby easier to re-use.

I hope that answered your question.

Update
I know there was a terminology for this, just could think of it. Having duplicate code is called "a DRY-violation". DRY stands for Don't Repeat Yourself which is a principle of software development aimed at reducing repetition of information of all kinds, especially useful in multi-tier architectures.
More information: DRY on Wikipedia

这篇关于在通用应用程序上分离iPhone和iPad类有什么优势吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆