newable

Dependency injection when the class created also needs runtime values?

空扰寡人 提交于 2019-12-30 03:27:07
问题 Assume you divide up your systems in Value objects and Services objects (as suggested in "Growing Object-Oriented Software, Guided by Tests". Misko Hevery calls these "newables" and "injectables". What happens when one of your value objects suddenly needs to access a service to implement it's methods? Let's say you have a nice simple Value object. It's immutable, holds a few bits of information and that's about it. Let's say we use it something like this: CreditCard card = new CreditCard(

How to specify any newable type in TypeScript?

痞子三分冷 提交于 2019-12-19 03:18:13
问题 I tried with this but it doesn't work. Foo is just a test of what works. Bar is the real try, it should receive any newable type but subclasses of Object isn't valid for that purpose. class A { } class B { public Foo(newable: typeof A):void { } public Bar(newable: typeof Object):void { } } var b = new B(); b.Foo(A); b.Bar(A); // <- error here 回答1: You can use { new(...args: any[]): any; } to allow any object with a constructor with any arguments. class A { } class B { public Foo(newable:

ViewHelper newable/injectable dilemma

南楼画角 提交于 2019-12-10 17:28:37
问题 I'm trying to design an application following Misko Heverys insights. It's an interesting experiment and a challenge. Currently I'm struggling with my ViewHelper implementation. The ViewHelper decouples the model from the view. In my implementation it wraps the model and provides the API for the view to use. I'm using PHP, but I hope the implementation is readable for everyone: class PostViewHelper { private $postModel; public function __construct(PostModel $postModel) { $this->postModel =

Dependency injection when the class created also needs runtime values?

喜你入骨 提交于 2019-11-30 09:53:23
Assume you divide up your systems in Value objects and Services objects (as suggested in "Growing Object-Oriented Software, Guided by Tests". Misko Hevery calls these "newables" and "injectables". What happens when one of your value objects suddenly needs to access a service to implement it's methods? Let's say you have a nice simple Value object. It's immutable, holds a few bits of information and that's about it. Let's say we use it something like this: CreditCard card = new CreditCard("4111-1111-1111-1111", "07/10"); if (card.isValid()) { // do stuff } else { // don't do stuff } So far so