Comments for Miško Hevery http://misko.hevery.com Testability Explorer Thu, 20 Nov 2008 09:45:22 +0000 http://wordpress.org/?v=2.6.3 Comment on Clean Code Talks - Dependency Injection by Impariamo a rispettare la legge di Demetra « JugSalerno http://misko.hevery.com/2008/11/11/clean-code-talks-dependency-injection/#comment-347 Impariamo a rispettare la legge di Demetra « JugSalerno Tue, 18 Nov 2008 22:18:26 +0000 http://misko.hevery.com/?p=290#comment-347 [...] Clean Code Talks - Dependency Injection di Misko Havery [...] [...] Clean Code Talks - Dependency Injection di Misko Havery [...]

]]>
Comment on Singletons are Pathological Liars by My Unified Theory of Bugs | Miško Hevery http://misko.hevery.com/2008/08/17/singletons-are-pathological-liars/#comment-346 My Unified Theory of Bugs | Miško Hevery Mon, 17 Nov 2008 23:37:27 +0000 http://misko.hevery.com/?p=162#comment-346 [...] Injection –> makes wiring explicit (unlike singletons, globals or service [...] [...] Injection –> makes wiring explicit (unlike singletons, globals or service [...]

]]>
Comment on Breaking the Law of Demeter is Like Looking for a Needle in the Haystack by My Unified Theory of Bugs | Miško Hevery http://misko.hevery.com/2008/07/18/breaking-the-law-of-demeter-is-like-looking-for-a-needle-in-the-haystack/#comment-345 My Unified Theory of Bugs | Miško Hevery Mon, 17 Nov 2008 23:36:20 +0000 http://misko.hevery.com/?p=99#comment-345 [...] separation between classes (Testable Seems) –> clear separation between classes makes it less likely that a wiring problem is [...] [...] separation between classes (Testable Seems) –> clear separation between classes makes it less likely that a wiring problem is [...]

]]>
Comment on How to Think About the “new” Operator with Respect to Unit Testing by dholm.com » Blog Archive » Tumblelog: 081117 http://misko.hevery.com/2008/07/08/how-to-think-about-the-new-operator/#comment-344 dholm.com » Blog Archive » Tumblelog: 081117 Mon, 17 Nov 2008 07:07:03 +0000 http://s90424825.onlinehome.us/blog/?p=41#comment-344 [...] How to Think About the “new” Operator with Respect to Unit Testing is an excellent introduction to dependency injection and why you need it. Also read How to Write 3v1L, Untestable Code. [...] [...] How to Think About the “new” Operator with Respect to Unit Testing is an excellent introduction to dependency injection and why you need it. Also read How to Write 3v1L, Untestable Code. [...]

]]>
Comment on Clean Code Talks - Dependency Injection by Mark Roddy http://misko.hevery.com/2008/11/11/clean-code-talks-dependency-injection/#comment-343 Mark Roddy Sun, 16 Nov 2008 18:12:25 +0000 http://misko.hevery.com/?p=290#comment-343 Awesome talk. I thought the Document example in this video was a really clear without having the condescension found in typical "A car is an object" style explinations of OOP concepts. I wish I there was a video on S.O.L.I.D. that was this well done, hint hint. Awesome talk. I thought the Document example in this video was a really clear without having the condescension found in typical “A car is an object” style explinations of OOP concepts. I wish I there was a video on S.O.L.I.D. that was this well done, hint hint.

]]>
Comment on Ask! by Peter Gardner http://misko.hevery.com/your-suggestions/#comment-342 Peter Gardner Fri, 14 Nov 2008 19:48:11 +0000 http://misko.hevery.com/?page_id=122#comment-342 I was wondering if you are still maintaining the Flex Calendar project on google code. Do you consider it complete? I was wondering if you are still maintaining the Flex Calendar project on google code. Do you consider it complete?

]]>
Comment on Pass Around Ginormous Context Objects by misko http://misko.hevery.com/2008/10/27/pass-around-ginormous-context-objects/#comment-340 misko Thu, 13 Nov 2008 19:04:30 +0000 http://misko.hevery.com/?p=272#comment-340 Port number is injectable. You can very well make a binding for it and ask for it in constructor. I think I should clarify this more in future posts. To put it another way if you ask for a port in constructor there is never an ambiguity about what you are looking for. There is only one port. to contrast this with something like CreditCard. That is not really injectable since in a system you can have a lot of credit cards and the number of them is dynamic at run-time. -- Misko Port number is injectable. You can very well make a binding for it and ask for it in constructor. I think I should clarify this more in future posts. To put it another way if you ask for a port in constructor there is never an ambiguity about what you are looking for. There is only one port.

to contrast this with something like CreditCard. That is not really injectable since in a system you can have a lot of credit cards and the number of them is dynamic at run-time.

– Misko

]]>
Comment on Pass Around Ginormous Context Objects by Artem B http://misko.hevery.com/2008/10/27/pass-around-ginormous-context-objects/#comment-339 Artem B Thu, 13 Nov 2008 18:46:42 +0000 http://misko.hevery.com/?p=272#comment-339 Misko, I have read the post you recommended and it says: "However, Injectable can never ask for a non-Injectable (Newable) in its constructor." As far as I understand, the port is NOT an injectable, but the WebServer is. The problem I have is exactly the problem you mention here: "when you ask for things which Dependency Injection Frameworks can not provide". What do I do then? thanx, Artem. Misko,

I have read the post you recommended and it says:

“However, Injectable can never ask for a non-Injectable (Newable) in its constructor.”

As far as I understand, the port is NOT an injectable, but the WebServer is. The problem I have is exactly the problem you mention here: “when you ask for things which Dependency Injection Frameworks can not provide”. What do I do then?

thanx, Artem.

]]>
Comment on Pass Around Ginormous Context Objects by misko http://misko.hevery.com/2008/10/27/pass-around-ginormous-context-objects/#comment-338 misko Thu, 13 Nov 2008 18:06:08 +0000 http://misko.hevery.com/?p=272#comment-338 Hi Artem, Excellent question. Have a look at: http://misko.hevery.com/2008/09/30/to-new-or-not-to-new/ The key question is can a Dependency Injection Framework such as GUICE know what do you mean when you ask for @Port int portNumber. And the answer is yes, there is not ambiguity. (You need the annotation since there are lot of ints but only one @Port int) So the prfered way is to ask for the port number in the constructor. If you think about it it makes perfect sense. In order to instantiate a WebServer you need to know the port number. So ask for it in constructor. I think the trouble you can ge into is when you ask for things which Dependency Injection Frameworks can not provide. Such as a Song. Well there are houndreds of Songs in the system, which one do you want? And annotation does not help since the Song list is dynamic. -- Misko Hi Artem,

Excellent question. Have a look at: http://misko.hevery.com/2008/09/30/to-new-or-not-to-new/ The key question is can a Dependency Injection Framework such as GUICE know what do you mean when you ask for @Port int portNumber. And the answer is yes, there is not ambiguity. (You need the annotation since there are lot of ints but only one @Port int)

So the prfered way is to ask for the port number in the constructor. If you think about it it makes perfect sense. In order to instantiate a WebServer you need to know the port number. So ask for it in constructor.

I think the trouble you can ge into is when you ask for things which Dependency Injection Frameworks can not provide. Such as a Song. Well there are houndreds of Songs in the system, which one do you want? And annotation does not help since the Song list is dynamic.

– Misko

]]>
Comment on Pass Around Ginormous Context Objects by Artem B. http://misko.hevery.com/2008/10/27/pass-around-ginormous-context-objects/#comment-337 Artem B. Thu, 13 Nov 2008 06:25:43 +0000 http://misko.hevery.com/?p=272#comment-337 This is the point where I don't get it. Assume that you have a WebServer class that controls a web server instance. It has a constructer like WebServer (Configuration config) { this.port = config.getPort(); } This breaks the law of Demeter and I want to refator it. But hey, I can't move the port to the constructor. This way I will be mixing the service-objects with value objects. And my application factory will have to know how to get the port configuration out of a config file which means doing work in the factory. Another way to refactor it is to move the configuration options to the start() method like this. // This is a test code, not a production code WebServer server = new WebServer(); server.start(8080); But this obligates the callers to know what port they need to start the server on, which again breaks the law of Demeter, because they shouldn't need any configuration options they do not directly use. Please, advice me on a way to refactor the code with Dependency Injection and the Law of Demeter in mind. This is the point where I don’t get it.

Assume that you have a WebServer class that controls a web server instance. It has a constructer like

WebServer (Configuration config) {
this.port = config.getPort();
}

This breaks the law of Demeter and I want to refator it. But hey, I can’t move the port to the constructor. This way I will be mixing the service-objects with value objects. And my application factory will have to know how to get the port configuration out of a config file which means doing work in the factory.

Another way to refactor it is to move the configuration options to the start() method like this.

// This is a test code, not a production code
WebServer server = new WebServer();
server.start(8080);

But this obligates the callers to know what port they need to start the server on, which again breaks the law of Demeter, because they shouldn’t need any configuration options they do not directly use.

Please, advice me on a way to refactor the code with Dependency Injection and the Law of Demeter in mind.

]]>