模块化编程...... [英] Modular Programming...

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

问题描述

这就是场景:


我有一个包含几个表格的VB.Net项目。在Form1上我有超过

20个按钮。在每个按钮的点击事件中都写了一个非常长的代码,每个按钮都是

。现在我没有使用任何子程序。我的意思是说我是直接在点击事件中编写代码的
。所以它变得非常冗长

因此要找出一些问题或做出任何改变我必须

滚动很多。除了点击事件程序之外,还有其他可能写入代码的事件。这有点混乱。


我的问题是,如果我添加20个模块并命名它们是个好主意

Button1Code,Button2Code etc.etc 。并在所有这些程序中创建一个程序

,其中包含Button的点击事件代码。然后快速找到代码会更容易

。例如,我知道如果我必须在Button1的click事件中更改
,那么我必须转到Button1Code

模块(并检查其中的过程)等等..


这是一个好主意吗?你有什么建议。


提前致谢!

This is the scenario:

I have a VB.Net project comprising of a few Forms. On Form1 I have more than
20 buttons. There is a very lenghty code written in click event of each and
every button. Right now I haven''t used any sub procedure. I mean to say I am
writing the code directly in the click event. So it''s become very lengthy
and therefore to figure out some problem or make any changes I have to
scroll at lot. Also in addition to click event procedures there are may
other events where code is written. It''s kind of mess.

My question is would it be good idea if I add 20 Modules and name them
Button1Code, Button2Code etc.etc. and create one procedure in all of them
which will contain the code of Button''s click event. Then it would be easier
to quickly find out the code. For example I would know that if I have to
make changes in the click event of Button1 then I have to go to Button1Code
Module (and check the procedure in it), and so on..

Is this a good idea? What are your suggestions.

Thanks in advance!

推荐答案

不 - 那就太过分了。也许将一些功能抽象为

实用程序。模块可能有意义,取决于按钮

功能的相似程度。如果他们都在做同样的事情,那么显然应该构建一个/ b $ b方法/潜艇来利用这个。


嗯,告诉我们几个按钮代码的片段,这样我们就可以做出更好的判断。

" I_AM_DON_AND_YOU?" <我们** @ domain.com>在留言中写道

新闻:%2 **************** @ TK2MSFTNGP12.phx.gbl ...
No - that would be overkill. Perhaps abstracting some functionality into a
"utility" module might make sense, depending on how similar the button
functions are. If they are all doing the same thing, then obviously
methods/subs should be constructed to take advantage of this.

Well, show us a couple of snippets of button code so we can make a better
judgement.
"I_AM_DON_AND_YOU?" <us**@domain.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
这是场景:

我有一个包含几个表单的VB.Net项目。在Form1上,我有超过20个按钮的
。在每个
和每个按钮的点击事件中都写了一个非常长的代码。现在我没有使用任何子程序。我的意思是说我在b $ b上直接在click事件中编写代码。所以它变得非常冗长
因此找出一些问题或做出任何改变我必须滚动很多。除了单击事件过程之外,还可能有其他写入代码的事件。这有点混乱。

我的问题是,如果我添加20个模块并将其命名为Button1Code,Button2Code等等,那将是个好主意。并在所有这些程序中创建一个程序
将包含Button的点击事件的代码。然后就是
更容易快速找到代码。例如,我知道如果我必须在Button1的click事件中进行更改,那么我必须转到
Button1Code模块(并检查其中的过程),依此类推..
提前致谢!
This is the scenario:

I have a VB.Net project comprising of a few Forms. On Form1 I have more than 20 buttons. There is a very lenghty code written in click event of each and every button. Right now I haven''t used any sub procedure. I mean to say I am writing the code directly in the click event. So it''s become very lengthy
and therefore to figure out some problem or make any changes I have to
scroll at lot. Also in addition to click event procedures there are may
other events where code is written. It''s kind of mess.

My question is would it be good idea if I add 20 Modules and name them
Button1Code, Button2Code etc.etc. and create one procedure in all of them
which will contain the code of Button''s click event. Then it would be easier to quickly find out the code. For example I would know that if I have to
make changes in the click event of Button1 then I have to go to Button1Code Module (and check the procedure in it), and so on..

Is this a good idea? What are your suggestions.

Thanks in advance!



Don,

我倾向于通过直接的模块化编程来遵循OOP编程。

代码分为不同的类,其中每个类都是自己的单位

的责任


如何类似的是20个按钮中的每个按钮的代码?如果代码基本上是

除了一个或两个值,或一个或两个部分。我想

考虑创建一个继承自Button的新按钮类,一个或

两个值,每个按钮都是唯一的,我会创建这个类的属性。

我将制作一两个部分的活动。在表单上我将使用我的新

按钮类,设置每个按钮的属性是唯一的,表单

将处理任何独特的事件。新类中的click事件

有所有常用代码,它会使用事件或属性

来获取每个按钮的不同值。


如果我有相同的话多个表单上有20个按钮,然后我会考虑为每个按钮创建一个类,每个表单都会得到一个

类的实例。我不经常使用这个。


您可以在表单的代码中使用#region来帮助组织活动

处理程序。


一般来说,我不会将子程序(事件处理程序)从表单移动到模块

来组织我的代码,因为我很少有例程这么大使

表格的代码无法管理。


希望这有帮助

Jay


I_AM_DON_AND_YOU? <我们** @ domain.com>在留言中写道

新闻:%2 **************** @ TK2MSFTNGP12.phx.gbl ...
Don,
I tend to follow OOP programming over straight Modular programming. Where
code is broken out into different classes, where each class is its own "unit
of responsibility"

How similar is the code in each of the 20 buttons? If the code is largely
the same except for one or two values, or one or two sections. I would
consider creating a new button class that inherits from Button, the one or
two values that are unique per button I would make properties of this class.
The one or two sections I would make events. On the form I would use my new
button class, setting the properties per button that are unique, the form
would handle any unique events. The click event within the new class would
have all the common code, it would use either the events or the properties
for the distinct values per button.

If I have the "same" 20 buttons on multiple forms, then I would consider
create a class for each button, each form would get an instance of that
class. I don''t use this one very often.

You can use #region within your form''s code to help organize the event
handlers.

Generally I do not move a subroutine (event handler) from a form to a module
to organize my code as I rarely have routines so large that they make the
form''s code unmanageable.

Hope this helps
Jay

"I_AM_DON_AND_YOU?" <us**@domain.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
这是场景:

我有一个包含几个表单的VB.Net项目。在Form1上,我有超过20个按钮的
。在每个
和每个按钮的点击事件中都写了一个非常长的代码。现在我没有使用任何子程序。我的意思是说我在b $ b上直接在click事件中编写代码。所以它变得非常冗长
因此找出一些问题或做出任何改变我必须滚动很多。除了单击事件过程之外,还可能有其他写入代码的事件。这有点混乱。

我的问题是,如果我添加20个模块并将其命名为Button1Code,Button2Code等等,那将是个好主意。并在所有这些程序中创建一个程序
将包含Button的点击事件的代码。然后就是
更容易快速找到代码。例如,我知道如果我必须在Button1的click事件中进行更改,那么我必须转到
Button1Code模块(并检查其中的过程),依此类推..
提前致谢!
This is the scenario:

I have a VB.Net project comprising of a few Forms. On Form1 I have more than 20 buttons. There is a very lenghty code written in click event of each and every button. Right now I haven''t used any sub procedure. I mean to say I am writing the code directly in the click event. So it''s become very lengthy
and therefore to figure out some problem or make any changes I have to
scroll at lot. Also in addition to click event procedures there are may
other events where code is written. It''s kind of mess.

My question is would it be good idea if I add 20 Modules and name them
Button1Code, Button2Code etc.etc. and create one procedure in all of them
which will contain the code of Button''s click event. Then it would be easier to quickly find out the code. For example I would know that if I have to
make changes in the click event of Button1 then I have to go to Button1Code Module (and check the procedure in it), and so on..

Is this a good idea? What are your suggestions.

Thanks in advance!



99%的代码都是在所有点击事件中编写的是不同的。为什么你会这么认为

会过度杀伤 ?


谢谢!


" Robin Tucker" <编号********** @ reallyidont.com>写在

消息新闻:bn ******************* @ news.demon.co.uk ...
99% of code written in all the click event is different. Why you think it
would "overkill" ?

Thanks!

"Robin Tucker" <id*************************@reallyidont.com> wrote in
message news:bn*******************@news.demon.co.uk...
不 - 那太过分了。也许将一些功能抽象为
autility。模块可能有意义,取决于按钮
功能的相似程度。如果他们都在做同样的事情,那么显然应该构建方法/子能够利用这一点。

那么,给我们看几个按钮代码片段,这样我们就可以制作更好的判断。

" I_AM_DON_AND_YOU?" <我们** @ domain.com>在消息中写道
新闻:%2 **************** @ TK2MSFTNGP12.phx.gbl ...
No - that would be overkill. Perhaps abstracting some functionality into a "utility" module might make sense, depending on how similar the button
functions are. If they are all doing the same thing, then obviously
methods/subs should be constructed to take advantage of this.

Well, show us a couple of snippets of button code so we can make a better
judgement.
"I_AM_DON_AND_YOU?" <us**@domain.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
这是情景:

我有一个包含几个表单的VB.Net项目。在Form1上我有
This is the scenario:

I have a VB.Net project comprising of a few Forms. On Form1 I have more than
20个按钮。每个按钮的每个
20 buttons. There is a very lenghty code written in click event of each


的点击事件都会写一个非常长的代码。现在我没有使用任何子程序。我的意思是说
我是
every button. Right now I haven''t used any sub procedure. I mean to say I am
直接在click事件中编写代码。所以它变得非常
writing the code directly in the click event. So it''s become very



很长,因此要找出一些问题或做出任何改变我必须滚动很多。除了单击事件过程之外,还可能有其他写入代码的事件。这有点混乱。

我的问题是,如果我添加20个模块并将其命名为Button1Code,Button2Code等等,那将是个好主意。并在
中创建一个过程,它们将包含Button的click事件代码。然后它将


lengthy and therefore to figure out some problem or make any changes I have to
scroll at lot. Also in addition to click event procedures there are may
other events where code is written. It''s kind of mess.

My question is would it be good idea if I add 20 Modules and name them
Button1Code, Button2Code etc.etc. and create one procedure in all of them which will contain the code of Button''s click event. Then it would be


更容易

来快速找到代码。例如,我知道如果我必须在Button1的click事件中进行更改,那么我必须转到
to quickly find out the code. For example I would know that if I have to
make changes in the click event of Button1 then I have to go to


Button1Code


Button1Code

Module(并检查其中的程序,等等..

这是一个好主意吗?您有什么建议。

提前致谢!
Module (and check the procedure in it), and so on..

Is this a good idea? What are your suggestions.

Thanks in advance!




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

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