在命名空间下组织 Apex 类 [英] Organizing Apex Classes under Namespace

查看:58
本文介绍了在命名空间下组织 Apex 类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Salesforce 中是否有任何方法可以在包或命名空间下对顶点类进行分组?我们可以将托管包用于内部组织目的吗?

Is there any way in Salesforce to group apex classes under a package or namespace? Can we use managed package for internal organization purpose?

推荐答案

这是 force.com 堆栈中的一个限制,即使不是不切实际,也会使中大型项目变得痛苦.使用受管包来获取包前缀并不能真正解决任何问题,因此不值得麻烦.

This is a limitation in the force.com stack that makes medium-large size projects painful, if not impractical. Using managed packages in order to get a package prefix doesn't really solve any problems, so it's not really worth the trouble.

我通常尝试将项目组织到一个平面级别的命名空间中.代替实际的命名空间,我会给每个可能的命名空间一个 3-5 个字符的名称,用作前缀.属于命名空间"的任何类都带有前缀.例如,如果我需要 payroll 命名空间,我会使用 PYRL 前缀.一个名为 PaycheckCalculator 的类变成了 PYRL_PaycheckCalculator.

I usually try to organize a project into one flat level of namespaces. In lieu of actual namespaces, I'll give each would-be-namespace a 3-5 character name, to be used as a prefix. Any class that belongs in the "namespace" gets prefixed. E.g., if I need a payroll namespace, I'd use a PYRL prefix. A class called PaycheckCalculator becomes PYRL_PaycheckCalculator.

这种约定的实际优点是它有助于防止名称冲突,并且在排序列表(例如在 IDE 中)或设置 > 开发 > Apex 类中查看时,类按其命名空间"分组

The practical advantage of this type of convention is it helps prevent name clashes and classes are grouped by their "namespace" when viewed in a sorted list, such as in an IDE, or Setup > Develop > Apex Classes

不幸的是,几个基本的面向对象原则仍然从根本上被打破.可能最重要的是每个类都对每个它具有可见性的其他类形成隐式依赖,即所有他们.

Unfortunately, several basic OO principles are still fundamentally broken. Probably the most important one is every class forms an implicit dependency on every other class it has visibility to, which is all of them.

我很想听听其他人是如何解决这个限制的.

I'd love to hear how others have worked around this limitation.

这篇关于在命名空间下组织 Apex 类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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