You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Forwarded conversation
Subject: new in constructor
------------------------
From: Christian Gruber <[email protected]>
Date: Fri, Apr 24, 2009 at 11:05 AM
To: Alex Eagle <[email protected]>, Misko Hevery <[email protected]>
Cc: [email protected]
So I have code that I'm testing the TE maven plugin on, and it's flagging
"new in the constructor". The "new" in this case is my call to super(...).
I can't avoid it in this case, since super() sets a private final variable
with the parameter - it's the only way in. So it's not really complaining
about "new" except insofar as it sees the hard-dependency of new - which is
inherent in implementation inheritance anyway. So I think either this
special case should be labelled differently (in which case we're saying
that inheritance is a non-mockable dependency and therefore is bad) or
displayed differently - perhaps by flagging that the class is inheriting
complexity.
But there's no way to mock the superclass (which is I guess the point) and
while it's often misused, it is a valid thing to use inheritance where
appropriate. Any thoughts on how to describe this?
the class in question is here:
http://code.google.com/p/israfil-micro/source/browse/trunk/israfil-micro-contain
er/src/main/java/net/israfil/micro/container/DefaultContainer.java
and it's superclass is here:
http://code.google.com/p/israfil-micro/source/browse/trunk/israfil-micro-contain
er/src/main/java/net/israfil/micro/container/AbstractContainer.java
(for the record, if you do look at it - it's Java 1.1 code so it can go on
a CLDC, so there's no post 1.2 JDK niceties.)
Christian.
----
Christian Edward Gruber - Software Excellence Ninja, Engineering Productivity
Google :::: +1 (212) 565-9427 [work] :::: +1 (289) 221-9839 [cell]
:::: [email protected]
----------
From: Miško Hevery <[email protected]>
Date: 2009/4/29
To: Christian Gruber <[email protected]>
Cc: Alex Eagle <[email protected]>, [email protected]
Hi Christian,
I am not sure what you are asking here. You have a class and a report flags
the call to super as expensive, (If I understand it correctly). Are you
looking for a name for the pattern?
-- Misko
----------
From: Christian Edward Gruber <[email protected]>
Date: Wed, Apr 29, 2009 at 9:10 AM
To: [email protected]
More or less. The case shows up as "new" (which it is, in Java), but
it's an implicit new in the code because it's a super() call. So
there are two things:
1. Name it differently so that it's clear what cause is being
identified - a lot of java programmers wouldn't equate super() with
"new"
2. I'm wondering about the costs. If I have
public class MySuperClass {
private final Service1 service;
public MySuperClass(Service1 service) { this.service = service; }
public Object aMethod() {
return process(service.doSomething());
}
...
}
public class MySubClass extends MySuperClass {
private final Service2 service2;
public MySubClass(Service1 service, Service2 service2) {
super(service);
this.service2 = service2;
}
public Object doSomeOtherThing() {
return process(service2.doSomeOtherThing());
}
....
}
This case has some additional complexity because of the parent, but
from a testability perspective, the constructors nly assign to final
variables, and everything is mockable except for the actual real
methods, and they do a minimum of work that's additive, and that
should count. But the new in the constructor is given a fixed cost
that seems more expensive than the actual cost-to-testability here.
(You can always argue that I can re-work this into composition and
delegation, but I'm presuming some logical API that follows LSP and
really does need to have inheritance to be reasonably structured)
cheers,
Christian.
Christian Edward Gruber
e-mail: [email protected]
weblog: http://www.geekinasuit.com/
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Testability Explorer" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/testability-explorer?hl=en
-~----------~----~----~----~------~----~------~--~---
----------
From: Misko Hevery <[email protected]>
Date: Wed, Apr 29, 2009 at 9:13 AM
To: [email protected]
Ohh now I get it call to super comes over as new. You are right that is not
obvious.
Yeah, we should name that a bit different.
-- Misko
Original issue reported on code.google.com by aeagle22206 on 4 May 2009 at 9:14
The text was updated successfully, but these errors were encountered:
Original issue reported on code.google.com by
aeagle22206
on 4 May 2009 at 9:14The text was updated successfully, but these errors were encountered: