Access to variables and methods of a module in a multi-module program
39 观看
1回复
10 作者的声誉
I have a modular program I am writing that aims to have modules that are fully functional as standalone units in conjunction with the core program.
This entails the program not breaking at all when a new module is "plugged in" or removed, and requiring no change to any other code for the program to compile and execute with or without some module.
My question is, should I have public getters and setters for all variables in all modules, and make all methods public, so that if a developer needs to access or change a variable (for example) in some module while developing their own module, they can do so without having to change the access modifiers, or should I reconsider my design?
Thank you in advance!
作者: nanoandrew4 的来源 发布者: 2017 年 12 月 27 日回应 1
0像
8194 作者的声誉
I will try to answer based on my understanding of your question as long as I need to help you. if you still need to ask anything, please leave a comment otherwise don't forget to rate my answer.
Access modifiers (public, private, etc
) were built to achieve abstraction and encapsulations
within your classes, both of them are key concepts of object oriented programming. so you have to analyze your requirements what you should reveal or disclose to the outside world especially if you want to ship your code and be used in different systems and you don't need other developers to change some properties which are used internally only for example something like database connection string
.
Modular where you define your public functionalities through interfaces and implement those interfaces.
Also, one principle it came to my mind where you should favor composition over inheritance to to avoid lots of code changes and breaks and dependencies.
Dependency Injection frameworks helps you to inject your modules, for example Spring framework came with dependency injection.
All of these principles will achieve
Open-close
andLiscov substitution
principles that target to make it easy and open to scale and extend your code easily and still keep your system close for modification.
Now it should come to design patterns where you should architect your components together, still it is based in your requirements where you can use Factory Method
for example in case you have one factory building multiple types of objects. Strategy
where you need to change the behavior at runtime based on user activaties, ..etc.
the answer even should be more longer than this however I tried to gave a glimpse where you should search and continue from here.
作者: Muhammad Soliman 发布者: 2017 年 12 月 27 日来自类别的问题 :
- java Java和C#中的int和Integer有什么区别?
- java 如何在Java中确定路由器/网关的IP?
- java 根据XSD文件验证XML文件的最佳方法是什么?
- java 如何整理整数除法的结果?
- java 将List <Integer>转换为List <String>
- java 为什么我不能在接口中声明静态方法?
- java 关闭电脑
- java 如何用Java播放声音?
- java 何时选择已检查和未检查的例外
- java 在Java中覆盖equals和hashCode时应该考虑哪些问题?
- modularity 如何构建express.js应用程序?
- modularity Clauset-Newman-Moore社区检测实施
- modularity Angular2模块化视图
- modularity 如何在Raml中的外部文件中定义类型的数组?
- modularity 使用Gradle将模块化库发布到Maven
- modularity 角度:基于客户的不同内容和布局
- modularity 面向对象的C-struct + pro's and cons中的变量
- modularity node.js管理频繁更改的本地依赖项
- modularity 每当MEF实例化(导出)新对象时如何执行动作?
- modularity 多实体扩展