好的设计 - 例子 [英] Good Design - Example

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

问题描述

我是OO Design的新手,我正在开始编写我的第一个C#

计划。鉴于OO编程的复杂性,我想通过这个组来运行

的东西并得到一般的输入。


我的例子是一个名为HijackThis的程序。我相信很多人都很熟悉

它是一个间谍软件清除工具。该程序在Windows计算机上查看超过20个地方

,以查看启动的内容(可选择删除

违规软件)。该程序可以删除浏览器帮助对象,浏览器主页设置,注册表运行键中的程序等。


我的第一个问题 - 你怎么做认为作者构建了这个程序?

将程序分成20个类,每个问题一个

区域,是否足够?这似乎是很多课程,因为每个问题都不会太复杂。是否应该避免额外的课程

,因为它们很简单?如果是这样,我需要巩固,

然后我该怎么做?我会把所有东西都归成一个庞大的课程吗?

为什么?我在哪里画线?


第二个问题 - 在面向动作的编程中,我们提出了一堆可重复使用的不同功能,如b
作为通用的

数据库访问函数或通用的ftp函数。在这个例子中,如果

我们使用20个类,每个类可能会有很多相同的方法代码

来访问注册表。这是否意味着我需要一个具有

公共方法的注册表类来操作注册表?如果我理解OO编程的推力,那么主要目标是该类可以重用,而不是与其他类或组件相关联(耦合)。这样的注册表

类似乎不会违反OO原则。但是这类课程的文件似乎很少。您会认为这样的常见操作会有很多

示例类。我不能帮助,但是不知道是否有什么东西没有沉入我豌豆大小的脑中。


第三个问题 - 我想复制HijackThis的BHO部分,

这将是一个具有备份功能的基本BHO移除器和一个简单的

接口。你个人会如何设计这样一个程序?


经过几年的其他编程后转移我的想法。方式

证明比我想象的更难(但我到了那里,虽然

慢慢地)。我公司里没有人做面向对象的编程,所以我没有任何人可以问。非常感谢你的帮助。


-KV

I''m new to OO Design, and I''m fixing to start writing my very first C#
program. Given the complexity of OO programming, I would like to run
something by this group and get general input.

My example is a program called HijackThis. I''m sure many are familiar
that it is a spyware removal tool. The program looks at over 20 places
on Windows computers to see what is starting (with options to remove the
offending software). The program can remove browser helper objects,
browser homepage settings, programs in the run key of the registry, etc.

My first question - How do you think the author structured this program?
Would dividing the program up into 20 classes, one for each problem
area, be sufficient? That seems like a lot of classes, given that each
problem isn''t too complicated. Should extra classes be avoided just
because they are simple? If that''s the case, and I need to consolidate,
then how would I do it? Would I lump everything into one massive class?
Why? Where do I draw the line?

Second question - in action-oriented programming, we come up with a
bunch of different functions that are reusable, such as a generic
database access function or a generic ftp function. In this example, if
we use 20 classes, each class will likely much of the same method code
to access the registry. Does that mean I need a registry class with
public methods to manipulate the registry? If I understand the thrust
of OO programming, the main goal is that the class be reusable and not
dependent (coupled) with other classes or components. Such a registry
class seems like it wouldn''t violate OO principles. But documentation
on such a class seems scarce. You would think there would be many
example classes out there for such a common operation. I can''t help but
wonder if something hasn''t sunken into my pea-sized brain.

Third question - I want to duplicate the BHO portion of HijackThis,
which would be a basic BHO remover with backup capabilities and a simple
interface. How would you, personally, design such a program?

Shifting my thinking after several years of programming the "other" way
is proving more difficult than I imagined (but I''m getting there, albeit
slowly). Nobody in my company does object-oriented programming, so I
don''t have anybody to ask. Your help would be greatly appreciated.

-KV

推荐答案

你的问题相当模糊最小。一些关键短语。


常识:

了解问题:

规划:

设计:

TestPlan:

重构:

重新设计

TestPlan:

重新测试

实施:

调试


-

OHM(Terry Burns)*使用以下内容给我发电子邮件*


Dim ch()如Char =" ufssz / cvsotAhsfbuTpmvujpotXjui / OFU" .ToCharArray()

For i As Int32 = 0 to ch.Length - 1

ch(i)= Convert.ToChar(Convert.ToInt16(ch(i)) - 1)

下一页

Process.Start(" mailto:"& New String(ch))

-

" KV" < NA ***** @ yahoo.com>在消息中写道

新闻:10 ************* @ corp.supernews.com ...
Your question is rather nebulous to say the least. Some key phrases for you.

Common Sense:
Understand the Problem:
Planning:
Design:
TestPlan:
Refactoring:
Re-Design
TestPlan:
Re-test
Implementation:
Debugging


--
OHM ( Terry Burns ) * Use the following to email me *

Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
--
"KV" <na*****@yahoo.com> wrote in message
news:10*************@corp.supernews.com...
我是新来的OO设计,我正在开始编写我的第一个C#
程序。鉴于OO编程的复杂性,我想通过这个小组运行一些东西并得到一般性的输入。

我的例子是一个名为HijackThis的程序。我相信很多人都很熟悉这是一个间谍软件清除工具。该程序在Windows计算机上查看超过20个位置,以查看启动的内容(可选择删除违规软件)。该程序可以删除浏览器帮助程序对象,浏览器主页设置,注册表运行键中的程序等。

我的第一个问题 - 您认为作者是如何构建此程序的?将程序划分为20个类,每个问题区域一个,是否足够?这似乎是很多课程,因为每个问题都不是太复杂。是否应该避免额外的课程因为它们很简单?如果是这样的话,我需要巩固,那么我该怎么做呢?我会把所有东西都集成到一个庞大的课程中吗?
为什么?我在哪里划线?

第二个问题 - 在面向行动的编程中,我们提出了一堆可重用的不同功能,例如通用的数据库访问功能或通用ftp功能。在这个例子中,如果我们使用20个类,每个类可能会有很多相同的方法代码来访问注册表。这是否意味着我需要一个具有
公共方法的注册表类来操作注册表?如果我理解OO编程的主旨,那么主要目标是该类可以重用,而不依赖于(耦合)其他类或组件。这样的注册表类似乎不会违反OO原则。但是关于这样一个类的文档似乎很少。您会认为这样的常见操作会有很多
示例类。我无法帮助,而是想知道是否有什么东西没有沉入我豌豆大小的脑中。

第三个问题 - 我想复制HijackThis的BHO部分,这将是一个基本的BHO卸妆,具有备份功能和简单的界面。你个人如何设计这样一个程序?

经过几年的其他程序设计后改变了我的想法。
比我想象的要困难(但是我要到了那里,虽然很慢)。我公司里没有人做面向对象的编程,所以我没有人问。非常感谢您的帮助。

-KV
I''m new to OO Design, and I''m fixing to start writing my very first C#
program. Given the complexity of OO programming, I would like to run
something by this group and get general input.

My example is a program called HijackThis. I''m sure many are familiar
that it is a spyware removal tool. The program looks at over 20 places
on Windows computers to see what is starting (with options to remove the
offending software). The program can remove browser helper objects,
browser homepage settings, programs in the run key of the registry, etc.

My first question - How do you think the author structured this program?
Would dividing the program up into 20 classes, one for each problem
area, be sufficient? That seems like a lot of classes, given that each
problem isn''t too complicated. Should extra classes be avoided just
because they are simple? If that''s the case, and I need to consolidate,
then how would I do it? Would I lump everything into one massive class?
Why? Where do I draw the line?

Second question - in action-oriented programming, we come up with a
bunch of different functions that are reusable, such as a generic
database access function or a generic ftp function. In this example, if
we use 20 classes, each class will likely much of the same method code
to access the registry. Does that mean I need a registry class with
public methods to manipulate the registry? If I understand the thrust
of OO programming, the main goal is that the class be reusable and not
dependent (coupled) with other classes or components. Such a registry
class seems like it wouldn''t violate OO principles. But documentation
on such a class seems scarce. You would think there would be many
example classes out there for such a common operation. I can''t help but
wonder if something hasn''t sunken into my pea-sized brain.

Third question - I want to duplicate the BHO portion of HijackThis,
which would be a basic BHO remover with backup capabilities and a simple
interface. How would you, personally, design such a program?

Shifting my thinking after several years of programming the "other" way
is proving more difficult than I imagined (but I''m getting there, albeit
slowly). Nobody in my company does object-oriented programming, so I
don''t have anybody to ask. Your help would be greatly appreciated.

-KV






" KV"写道:


"KV" wrote:
我是OO Design的新手,我正在开始编写我的第一个C#
程序。鉴于OO编程的复杂性,我想通过这个小组运行一些东西并得到一般性的输入。

我的例子是一个名为HijackThis的程序。我相信很多人都很熟悉这是一个间谍软件清除工具。该程序在Windows计算机上查看超过20个位置,以查看启动的内容(可选择删除违规软件)。该程序可以删除浏览器帮助程序对象,浏览器主页设置,注册表运行键中的程序等。

我的第一个问题 - 您认为作者是如何构建此程序的?将程序划分为20个类,每个问题区域一个,是否足够?这似乎是很多课程,因为每个问题都不是太复杂。是否应该避免额外的课程因为它们很简单?如果是这样的话,我需要巩固,那么我该怎么做呢?我会把所有东西都集成到一个庞大的课程中吗?
为什么?我在哪里划线?


我看看项目和OOD是这样的:

需要完成哪些任务然后再看看
$ b之间的关系$ b他们 - 我需要接口什么?这些接口中的每一个通常都是一个对象或对象集合 - 就像在gui中一样。那么什么是

我的目标 - 我需要做什么 - 这通常会将appart分解为1个或更多

数据组件(对象)及其相关方法。然后我怎么去

将它们整合在一起控制逻辑/对象 - 基本上我把事情分解成:

接口对象(io,gui等),数据对象(在memeory使用中),并控制

对象(让它们全部挂在一起)。我将事物尽可能地分组

尽可能或有意义。

第二个问题 - 在面向行动的编程中,我们提出了一堆不同的功能可重用的,例如通用的数据库访问函数或通用的ftp函数。在这个例子中,如果我们使用20个类,每个类可能会有很多相同的方法代码来访问注册表。这是否意味着我需要一个具有
公共方法的注册表类来操作注册表?


是的,注册表对象是一件好事。尝试尽可能地保持粒度,尽管在某些方面也是如此,你只需要b / b
必须使用你自己的偏好 - 而不是20个tiney对象可能是一个

中等实用程序对象可能是有序的。

如果我理解OO编程的主旨,那么主要目标是该类可以重用而不依赖(耦合)其他类或者组件。这样的注册表类似乎不会违反OO原则。但是关于这样一个类的文档似乎很少。您会认为这样的常见操作会有很多
示例类。我不能不知道是否有什么东西没有沉入我的豌豆大小的脑中。


通常这会产生 - 最终 - 在代码库中你可以为每个项目使用/修改
并加快你的编码时间。它可以在现实中成为无用或噩梦,如果没有记录得好并且好好地敲响了。

第三个问题 - 我想复制BHO HijackThis的一部分,
这将是一个基本的BHO去除器,具有备份功能和简单的界面。你个人如何设计这样的程序?


我不知道BHO是什么,但基本上我设计的所有程序都是一样的

方式 - 接口,数据,控制。

经过几年的其他编程后改变我的想法。
比我想象的要困难(但是我要到了那里,虽然很慢)。


我很同情,我花了很长时间甚至把它拉到了windows / b
思考的模型 - 代码路径基本上死了直到外部事件带来了生活中的b $ b。现在完整的OOD更容易实现,我实际上在大学时倾向于使用它,但在现实世界中并没有使用它好几年。

如果我的啰嗦有帮助,那么好,如果没有,可能比我更有技巧b
有一个机会。在任何一种情况下:祝你好运。

公司里没有人做面向对象的编程,所以我没有人问。非常感谢您的帮助。

-KV
I''m new to OO Design, and I''m fixing to start writing my very first C#
program. Given the complexity of OO programming, I would like to run
something by this group and get general input.

My example is a program called HijackThis. I''m sure many are familiar
that it is a spyware removal tool. The program looks at over 20 places
on Windows computers to see what is starting (with options to remove the
offending software). The program can remove browser helper objects,
browser homepage settings, programs in the run key of the registry, etc.

My first question - How do you think the author structured this program?
Would dividing the program up into 20 classes, one for each problem
area, be sufficient? That seems like a lot of classes, given that each
problem isn''t too complicated. Should extra classes be avoided just
because they are simple? If that''s the case, and I need to consolidate,
then how would I do it? Would I lump everything into one massive class?
Why? Where do I draw the line?
I take a look at project and OOD like this:
What tasks need to be done and then look at the relationship between
them-What do i need to interface to? Each of those interfaces are usually an
object, or collection of objects--like in a gui, by themselves. Then what is
my objective--what do i need to do--this usually breaks appart into 1 or more
data components (objects) and thier associated methods. Then how am i going
to fit it all together control logic/objects--basically i break things into:
interface objects (io, gui, etc), data object (in memeory use), and control
objects (make it all hang together). I keep things as homogeniously grouped
as possible or makes sense.

Second question - in action-oriented programming, we come up with a
bunch of different functions that are reusable, such as a generic
database access function or a generic ftp function. In this example, if
we use 20 classes, each class will likely much of the same method code
to access the registry. Does that mean I need a registry class with
public methods to manipulate the registry?
yes, a registry object would be a good thing to have. try to keep things as
cohesive as possible in their granularity, but at some point too, you just
have to use some of your own prefernce--instead of 20 tiney objects maybe one
moderate "utility" object might be in order.
If I understand the thrust
of OO programming, the main goal is that the class be reusable and not
dependent (coupled) with other classes or components. Such a registry
class seems like it wouldn''t violate OO principles. But documentation
on such a class seems scarce. You would think there would be many
example classes out there for such a common operation. I can''t help but
wonder if something hasn''t sunken into my pea-sized brain.
Generally this will result--eventually--in a code base that you can
use/modify for each project and will speed up your coding time. It can in
reality become all but useless or nightmare if not documented well and
militantly.

Third question - I want to duplicate the BHO portion of HijackThis,
which would be a basic BHO remover with backup capabilities and a simple
interface. How would you, personally, design such a program?

I don''t know what a BHO is, but basically I design all my programs the same
way--interfaces, data, control.
Shifting my thinking after several years of programming the "other" way
is proving more difficult than I imagined (but I''m getting there, albeit
slowly).
I sympathize, it took me quite a while to shit even to the windows model of
thinking--code paths that sit essentially dead until an external event brings
them to life. Now the full OOD is a little easier to do, I actually leaned
OOD in college, but didn''t get to use it for several years in the real world.

If my ranblings have helped, good, if not may another more skilled than I
have a shot. In either case: best of luck to you.
Nobody in my company does object-oriented programming, so I
don''t have anybody to ask. Your help would be greatly appreciated.

-KV



KV写道:
KV wrote:
我是OO Design的新手,我正在着手开始编写我的第一个C#程序。鉴于OO编程的复杂性,我想通过这个小组运行一些东西并获得一般性的输入。

我的例子是一个名为HijackThis的程序。我相信很多人都很熟悉这是一个间谍软件清除工具。该程序在Windows计算机上查看超过20个位置,以查看启动的内容(使用
选项删除有问题的软件)。该程序可以删除浏览器帮助对象,浏览器主页设置,注册表运行键中的程序等。

我的第一个问题 - 您如何看待作者结构化这个
程序?将程序划分为20个班级,每个问题区域一个,是否足够?这似乎是很多课程,因为每个问题都不是太复杂。是否应该避免额外的课程,因为它们很简单?如果是这样,我需要巩固,那我该怎么做呢?我会把所有东西都归结为一个庞大的课程吗?为什么?我在哪里划线?

第二个问题 - 在面向行动的编程中,我们提出了一堆可重用的不同功能,例如通用的数据库访问功能或通用ftp功能。在这个例子中,如果我们使用20个类,每个类可能会有很多相同的方法来访问注册表。这是否意味着我需要一个注册表类用公共方法来操作注册表?如果我理解OO编程的主旨,那么主要目标是该类可以重用,而不是依赖(耦合)其他类或组件。这样的注册表类似乎不会违反OO原则。但是关于这样一个类的文档似乎很少。你会认为那里有许多例子类可用于这种常见的操作。
我不禁想知道是不是有什么东西没有沉入我的豌豆大小的脑中。

第三个问题 - 我想复制HijackThis的BHO部分,
这将是一个具有备份功能和简单界面的基本BHO移除器。你个人会如何设计这样一个程序?

经过几年的编程后,改变我的想法其他的方式比我想象的更难(但我是到那儿,
虽然很慢)。我公司里没有人做面向对象的编程,所以我没有人问。非常感谢你的帮助。

-KV
I''m new to OO Design, and I''m fixing to start writing my very first
C# program. Given the complexity of OO programming, I would like to
run something by this group and get general input.

My example is a program called HijackThis. I''m sure many are
familiar that it is a spyware removal tool. The program looks at
over 20 places on Windows computers to see what is starting (with
options to remove the offending software). The program can remove
browser helper objects, browser homepage settings, programs in the
run key of the registry, etc.

My first question - How do you think the author structured this
program? Would dividing the program up into 20 classes, one for
each problem area, be sufficient? That seems like a lot of classes,
given that each problem isn''t too complicated. Should extra classes
be avoided just because they are simple? If that''s the case, and I
need to consolidate, then how would I do it? Would I lump everything
into one massive class? Why? Where do I draw the line?

Second question - in action-oriented programming, we come up with a
bunch of different functions that are reusable, such as a generic
database access function or a generic ftp function. In this example,
if we use 20 classes, each class will likely much of the same method
code to access the registry. Does that mean I need a registry class
with public methods to manipulate the registry? If I understand the
thrust of OO programming, the main goal is that the class be reusable
and not dependent (coupled) with other classes or components. Such a
registry class seems like it wouldn''t violate OO principles. But
documentation on such a class seems scarce. You would think there
would be many example classes out there for such a common operation.
I can''t help but wonder if something hasn''t sunken into my pea-sized
brain.

Third question - I want to duplicate the BHO portion of HijackThis,
which would be a basic BHO remover with backup capabilities and a
simple interface. How would you, personally, design such a program?

Shifting my thinking after several years of programming the "other"
way is proving more difficult than I imagined (but I''m getting there,
albeit slowly). Nobody in my company does object-oriented
programming, so I don''t have anybody to ask. Your help would be
greatly appreciated.

-KV




嗨KV,


我很遗憾你没有从你的

问题得到更多回复说实话。


不要害怕有很多小的特定类,当有疑问时,b $ b看看.NET框架类本身,它们(小)很小,而且非常特定于特定任务。顺便说一下20+是*不是*很多,

a很多都是几万;-)


你引用的例子非常关于为什么你会以这种方式构建你的课程的好例子,关于广告软件的事情就是你知道如何阻止一个移动目标的b
$ b

的一部分,他们去做其他事情,所以你的20多个任务随着时间的推移可能

现在变成30+如果这是一个巨型课程,它会很快成为

凌乱而且难以维护。


如果你想冒险,你可以设计它,以便

be只需将新程序集放入

插件即可添加新任务。目录,这样你就可以让应用程序保持最新状态来对抗

最新的威胁,(但要小心你不要再提供

恶意软件的另一种途径劫持你的机器)


现在关于注册表访问的具体问题,如果一个大的

数量的任务需要访问注册表的特定方法

类,您可能会从注册表类继承您的任务(需要注册表

访问权限)。在这些类型的应用程序中,你可以得到一个带有baseTask类的类heirachy,并且在轨道上有不同的

分支,即

TaskBase - > RegistryTask - > RemoveFromRunNodeTask

TaskBase - > RegistryTask - > RemoveFromRunOnceNodeTask

TaskBase - > ProfileTask - > RemoveFromSystemIniTask


等等


经验法则,让课程小巧,简单,易于维护。


问Tim。



Hi KV,

I am kind of surprised you didn''t get more of a response from your
question to be honest.

Don''t be afraid to have lots of small specific classes, when in doubt
look at the .NET framework classes themselves, they are (mosty) small
and very specific to a particular task. By the way 20+ is *not* a lot,
a few tens of thousands are a lot ;-)

Your example that you cite is a very good example as to why you would
architect your classes that way, the thing about adware is that you are
fighting a moving target, once you figure out how to stop one part of
it they go and do somthing else, so your 20+ tasks over time might
become 30+ now if this is all in one mega class, it will quickly become
messy and unmaintainable.

If you wanted to be adventurous you could design it in such a way as to
be able to add new tasks by just dropping a new assembly into a
"plugins" directory so that you can keep the app up to date to combat
the latest threat, (be careful though that you don''t then provide
another avenue for the malware to hijack your machine)

Now regarding the specific question of registry access, if a large
number of the tasks require accessing a specific method of a registry
class, you might look at inheriting your tasks (that require registry
access) from your registry class. In these types of applications you
may end up with a class heirachy with a baseTask class and varying
branches of of that down the track i.e.

TaskBase -> RegistryTask -> RemoveFromRunNodeTask
TaskBase -> RegistryTask -> RemoveFromRunOnceNodeTask
TaskBase -> ProfileTask -> RemoveFromSystemIniTask

etc etc

rule of thumb, keep classes small, simple and maintainable.

Regards Tim.


这篇关于好的设计 - 例子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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