java中的包和类设计以及访问粒度

发布于 2024-11-05 23:48:11 字数 584 浏览 1 评论 0原文

我在一个团队中工作,我们决定将其分成几组,这样每个组都会提供一个可以在不同 JVM 中运行的 jar 文件。在我的组中定义“A 类”时,我发现其他组只会访问一些属性和设置器,在运行时,类型 A 的对象存储在缓存中并由团队的其他成员检索。为了提供必要的粒度,我决定创建两个 jar:

A1.jar,它应该由团队的其他成员使用,并且包含将在缓存中存储和检索的 A 类。

A2.jar 将包含从 A 派生的 B 类和我的业务代码,该 jar 不会被团队的其他成员使用,但可以通过某些 SOA 接口访问。

我将团队其他成员无法访问的设置器和属性移至 B 级,但我有一些疑问。

如果某些组需要对 A 类进行不同的访问(假设他们可以设置其他人不能设置的某些属性)怎么办?

除了 protected、public、private 关键字之外,是否有任何模式可以根据类用户的包来拒绝访问类中的某些属性?

pd:我所说的组是指开发团队中提供一些 jar 文件的一组人员,这些组的构成反映了逻辑业务,当我说“访问”时,我指的是通过私有/受保护/公共对代码的静态访问/package 关键字,无论如何,我指的是与运行时属性相关的任何动态访问。

请原谅我的英语

I'm working in a team, we decided to divide the in groups so every group would deliver a jar file that would run in different JVM's. In defining 'Class A' in my group i found that other groups would access just some properties and setters, at runtime objects of type A are stored in a cache and retrieved by the rest of the team. To provide the necessary granularity i decided to create two jars:

A1.jar that should be used by the rest of the team and would include the Class A that would be stored and retrieved from the cache.

A2.jar that would contain both a B class derived from A and my business code, this jar wouldn't be used by the rest of the team but it would be accesed by some SOA interfaces.

The i moved the setters and properties not accesible by the rest of the team to class B but i've got some doubts.

What if some group needs different access to Class A (say they can set some property others cannot)?

Is there any pattern to deny access to some properties in a class based upon the package of the user of the class, aside from the protected, public, private keywords?

p.d: by group i mean some group of persons of the development team which delivers some jar file, the constituion of the groups reflects the logical business, when i say 'access' i mean static access to the code via the private/protected/public/package keywords, by any mean i meant any dynamic access related to runtime properties.

Please, excuse my english

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一个人练习一个人 2024-11-12 23:48:11

听起来继承和模块的用法很奇怪。相反,我会发布一个 API,它是一个接口或一组接口,可能还有一个工厂。

Sounds like an odd usage of inheritance and modules. I would instead publish an API that is an interface or a set of interfaces, and possibly a factory.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文