Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Inject the dependency into the methods that require ImportantClass
- Class Something {
- public Something()
- {
- //empty
- }
- public void A()
- {
- //do something without x
- }
- public void B(ImportantClass x)
- {
- //do something with x
- }
- public void C(ImportantClass x)
- {
- //do something with x
- }
- }
- //Inject the dependency into the constructor once
- Class Something {
- private ImportantClass _x
- public Something(ImportantClass x)
- {
- this._x = x;
- }
- public void A()
- {
- //do something without x
- }
- public void B()
- {
- //do something with this._x
- }
- public void C()
- {
- //do something with this._x
- }
- }
- class Foo {
- private final Bar _bar;
- Foo(Bar bar) {
- _bar=bar;
- }
- }
- public interface IFoo
- {
- void Do();
- }
- public class IFoo DefaultFoo : IFoo
- {
- public void Do()
- {
- }
- }
- public class UsesFoo
- {
- private IFoo foo;
- public IFoo Foo
- {
- set { this.foo = value; }
- }
- public UsesFoo()
- {
- this.Foo = new DefaultFoo();
- }
- public UsesFoo( IFoo foo )
- {
- this.Foo = foo;
- }
- public void DoFoo()
- {
- this.Foo.Do();
- }
- }
Add Comment
Please, Sign In to add comment