由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Java版 - Design options
相关主题
maven真是个好东东Runtime.exec() 问题
Apply lock on a class.help on this scope question
问一个关于access object instance的问题A question about inheritance
how to use JAVA to created named pipe under windows?怎么能够减少image上的锯齿?
这道题该走什么路在一个函数里把arraylist设为null 但是有问题
Talk a little more about How to lock a file发现 synchronized 的一个问题
Re: Entity EJB: anyone with real experienceJava大侠们:Hashtable help please!
Starter's problemstatic getInstance()
相关话题的讨论汇总
话题: rule话题: class话题: xml话题: design
进入Java版参与讨论
1 (共1页)
g**********y
发帖数: 14569
1
- A DocumentCenter class processes XML document.
- A bunch of classes *Rule derived from BaseRule class, which will apply some
rule to XML document.
So, I need to pass DocumentCenter instance to Rule classes.
Two options I can see:
1. Set DocumentCenter as Singleton
2. In main class, pass DocumentCenter instance to each Rule class.
Considering future expansion/maintenance, which way would you go? or you have
better solution?
m******t
发帖数: 2416
2

Being a Dependency Injection fan, I'd go with this one.

【在 g**********y 的大作中提到】
: - A DocumentCenter class processes XML document.
: - A bunch of classes *Rule derived from BaseRule class, which will apply some
: rule to XML document.
: So, I need to pass DocumentCenter instance to Rule classes.
: Two options I can see:
: 1. Set DocumentCenter as Singleton
: 2. In main class, pass DocumentCenter instance to each Rule class.
: Considering future expansion/maintenance, which way would you go? or you have
: better solution?

X****r
发帖数: 3557
3
lol.. this is a good one :)

【在 m******t 的大作中提到】
:
: Being a Dependency Injection fan, I'd go with this one.

m******t
发帖数: 2416
4

Self-mocking aside, the suggestion part was serious though...

【在 X****r 的大作中提到】
: lol.. this is a good one :)
w*******g
发帖数: 9932
5
option 1.
let BaseRule class call DocumentCenter to get an instance.

【在 g**********y 的大作中提到】
: - A DocumentCenter class processes XML document.
: - A bunch of classes *Rule derived from BaseRule class, which will apply some
: rule to XML document.
: So, I need to pass DocumentCenter instance to Rule classes.
: Two options I can see:
: 1. Set DocumentCenter as Singleton
: 2. In main class, pass DocumentCenter instance to each Rule class.
: Considering future expansion/maintenance, which way would you go? or you have
: better solution?

s*******k
发帖数: 20
6
Create a main class, say PIPE. Available action PIPE would do is FLOW through
each VALVE attached to it.
DocumentCenter is the entry VALVE attached to the PIPE. Then other RULEs.

【在 g**********y 的大作中提到】
: - A DocumentCenter class processes XML document.
: - A bunch of classes *Rule derived from BaseRule class, which will apply some
: rule to XML document.
: So, I need to pass DocumentCenter instance to Rule classes.
: Two options I can see:
: 1. Set DocumentCenter as Singleton
: 2. In main class, pass DocumentCenter instance to each Rule class.
: Considering future expansion/maintenance, which way would you go? or you have
: better solution?

m**c
发帖数: 90
7
Or using "Decorator Pattern" on "Rule" class:
...
Rule rule = new Rule3 (new Rule2( new Rule3())); // Decorator Pattern
DocumentCenter.getInstance().setRule(rule); // Manual "Dependency Injecti
on" ???
DocumentCenter.process(xmlDoc);
...
g**********y
发帖数: 14569
8
Good suggestion, leads me to Martin Fowler's page -- www.martinfowler.com/arti
cles/injection.html
Have a good reading today.

【在 m******t 的大作中提到】
:
: Self-mocking aside, the suggestion part was serious though...

g**********y
发帖数: 14569
9
I don't fully get the idea -- my question is how to pass DocumentCenter instan
ce to Rule. Pass DocumentCenter/Rule as valve is OK to me, but in this design,
how does Rule get DocumentCenter instance?

【在 s*******k 的大作中提到】
: Create a main class, say PIPE. Available action PIPE would do is FLOW through
: each VALVE attached to it.
: DocumentCenter is the entry VALVE attached to the PIPE. Then other RULEs.

g**********y
发帖数: 14569
10
Yeah, Decorator fits here nicely. My framework is on similiar track, just litt
le difference --
Configure all Rules in XML file like:




...

then in main program, I extract our all rules with "run=1" and use reflective
to apply all Rules to document. (BaseRule has a method apply())
As compared to Decorator, coding would be
NodeDocument doc1 = NodeDocument(origDoc);
DefDocument doc2 = DefDocument(doc1);
GuidDocument

【在 m**c 的大作中提到】
: Or using "Decorator Pattern" on "Rule" class:
: ...
: Rule rule = new Rule3 (new Rule2( new Rule3())); // Decorator Pattern
: DocumentCenter.getInstance().setRule(rule); // Manual "Dependency Injecti
: on" ???
: DocumentCenter.process(xmlDoc);
: ...

s*******k
发帖数: 20
11
Hehe, don't go for the idea of passing DocumentCenter instance to Rule.
I was thinking in the "other options" way, different entry point from ur initi
al design.

【在 g**********y 的大作中提到】
: Yeah, Decorator fits here nicely. My framework is on similiar track, just litt
: le difference --
: Configure all Rules in XML file like:
:
:
:
:
: ...
:

: then in main program, I extract our all rules with "run=1" and use reflective

1 (共1页)
进入Java版参与讨论
相关主题
static getInstance()这道题该走什么路
Converge of languages and design patternTalk a little more about How to lock a file
how to print the cllass name of an instance?Re: Entity EJB: anyone with real experience
question about GUIStarter's problem
maven真是个好东东Runtime.exec() 问题
Apply lock on a class.help on this scope question
问一个关于access object instance的问题A question about inheritance
how to use JAVA to created named pipe under windows?怎么能够减少image上的锯齿?
相关话题的讨论汇总
话题: rule话题: class话题: xml话题: design