Re: Newbie question anti-patterns and wicket, constructor component building

2010-06-15 Thread Jeremy Thomerson
>
>
> Well, the second version uses constructer injection.  Some frameworks
> prefer that approach.
>
> But, I see your point.
>

You should not be calling a service or dao directly in your constructor,
regardless of whether you are using dependency injection or not.  This is
bad.  That's what models are for.  Load data in models - not while
constructing an object.

-- 
Jeremy Thomerson
http://www.wickettraining.com


Re: Newbie question anti-patterns and wicket, constructor component building

2010-06-15 Thread Jeremy Thomerson
>
>
> Well, the second version uses constructer injection.  Some frameworks
> prefer that approach.
>
> But, I see your point.
>

You should not be calling a service or dao directly in your constructor,
regardless of whether you are using dependency injection or not.  This is
bad.  That's what models are for.  Load data in models - not while
constructing an object.

-- 
Jeremy Thomerson
http://www.wickettraining.com


RE: Newbie question anti-patterns and wicket, constructor component building

2010-06-15 Thread Brown, Berlin [GCG-PFS]
 

-Original Message-
From: Jeremy Thomerson [mailto:jer...@wickettraining.com] 
Sent: Tuesday, June 15, 2010 3:25 PM
To: users@wicket.apache.org
Subject: Re: Newbie question anti-patterns and wicket, constructor
component building

On Tue, Jun 15, 2010 at 2:11 PM, Brown, Berlin [GCG-PFS] <
berlin.br...@primerica.com> wrote:

> I am sorry, am just getting used to Wicket but I notice a lot of use 
> of calling a lot of code in the constructor.  Does it really matter?  
> I mention it because this kind of style makes it difficult to test 
> code because code in the constructor may fail and the object won't be 
> created.
>
> Should I just create a method and call that method in the constructor?
>

The constructor is supposed to construct the object.  In Wicket, this
also
(typically) means constructing the component hierarchy.  So, your
constructor should be doing things like add(new FooPanel("foo", new
SomeModel()));  It should NOT be doing things like:

List foos = SomeDao.loadAll();
new FooPanel("foo", foos);

That's the kind of code I see newbs putting in their constructor all the
time - and it should NOT be there.

--
Jeremy Thomerson
http://www.wickettraining.com

-

Well, the second version uses constructer injection.  Some frameworks
prefer that approach.

But, I see your point.


-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Newbie question anti-patterns and wicket, constructor component building

2010-06-15 Thread Jeremy Thomerson
On Tue, Jun 15, 2010 at 2:11 PM, Brown, Berlin [GCG-PFS] <
berlin.br...@primerica.com> wrote:

> I am sorry, am just getting used to Wicket but I notice a lot of use of
> calling a lot of code in the constructor.  Does it really matter?  I
> mention it because this kind of style makes it difficult to test code
> because code in the constructor may fail and the object won't be
> created.
>
> Should I just create a method and call that method in the constructor?
>

The constructor is supposed to construct the object.  In Wicket, this also
(typically) means constructing the component hierarchy.  So, your
constructor should be doing things like add(new FooPanel("foo", new
SomeModel()));  It should NOT be doing things like:

List foos = SomeDao.loadAll();
new FooPanel("foo", foos);

That's the kind of code I see newbs putting in their constructor all the
time - and it should NOT be there.

-- 
Jeremy Thomerson
http://www.wickettraining.com