良好的编程习惯 [英] Good programming practice

查看:75
本文介绍了良好的编程习惯的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个表单,通过该表单实例化了一个对象数组
类称为资源.我可以从
访问其所有方法 所述形式.我还实例化了类中的另一个对象
在相同的主要形式下称为时间表.每个资源对象
包含一个用于存储许多参数的数组.这些
需要使参数可用于对象计划,但是我
遇到了两难选择.按照正常的良好编程习惯
核心代码与用户界面代码分开,因此
该代码将被封装在所述类中.但是这些
两个类(以主形式实例化)可以传递此类信息
彼此之间?

谢谢

Hi,

I have a form, through which I have instantiated an array of objects
of a class called resource. I am able to access all its methods from
the said form. I have also instantiated another object from a class
called schedule under the same main form. Each resource object
contains an array used to store a number of parameters. These
parameters need to be made available for the object schedule however I
have encountered a dilemma. As per normal good programming practice
the core code is separated from the user interface code and therefore
the code is to be encapsulated in the said classes. But how can these
two classes (instantiated in the main form) can pass such information
between each other?

Thanks

推荐答案

将此内容读一遍
设计模式:模型视图演示器 [
give this one a read
Design Patterns: Model View Presenter[^]


我认为您正在描述一种情况,仅一次,在应用程序初始化时,日程表"的实例可能需要访问资源"的每个实例中的参数数组...对吗?听起来不像是您需要响应某些用户操作引发事件的情况.

但是,如果您的参数正在更新,实时那里的另一个故事,还有一个更复杂的故事.

因此,请澄清:

1.您是要隐藏除计划"以外的每个对象的整个参数集合吗?

2.和/或:您是否打算将对参数"类的实例的内部字段的访问限制为仅对计划"实例进行访问?

您是否熟悉在C#中创建仅定义"get"以隐藏对类中内部只读字段的访问的属性?
I think you are describing a scenario where, one-time-only, at initialization of the application, probably, the instance of the ''schedule'' needs access to the parameter array in each instance of a ''resource'' ... right ? Doesn''t sound like a case where you need to raise an event in response to some user action.

If, however, your parameters are getting updated, edited in real-time: another story there, and a much more complex one.

So, please clarify:

1. is it your intent to hide the entire parameters collection from every object except ''schedule'' ?

2. and/or: is it your intent to restrict access to the internal fields of instances of your ''parameter'' class to the ''schedule'' instance only ?

Are you familiar with creating Properties in C# that have only a ''get'' defined to hide access to an internal readonly field in a class ?


感谢您的建议.我已经阅读了Simon的帖子,还查看了BillWoodruff发表的评论.由于这对我来说是一种新方法,因此需要花一些时间进行自定义,但仍在不断进步.现在,我将与数据加载相关的方法从与视图相关联的那些流程中分离出来.我现在正在研究不同实体如何链接在一起.

在这个阶段,我认为这个问题可以标记为已结束.

谢谢
Thanks both for your suggestions. I have read Simon''s post and also reviewed comments posted by BillWoodruff. As this is a new approach for me it takes a while to get customed but doing progress. I now seperated the methods related to data loading from those processes associated with the view. I am now working on how the different entities link together.

At this stage I think that this question can be marked as closed.

Thanks


这篇关于良好的编程习惯的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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