Created
March 21, 2016 00:16
-
-
Save AlphaGit/11fc6d69a1d20b30fa2e to your computer and use it in GitHub Desktop.
Decoupled Producer/Consumer, renovating instances
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Consumer | |
{ | |
private Type _producerClass; | |
public Consumer(Type producerClass) | |
{ | |
if (!typeof (IProducer).IsAssignableFrom(producerClass)) | |
throw new ArgumentException("producerClass must be a IProducer type"); | |
_producerClass = producerClass; | |
} | |
public bool DoConsumption() | |
{ | |
var producer = Activator.CreateInstance(_producerClass) as IProducer; | |
var value = producer.DoProduction(); | |
return value != null; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IProducer | |
{ | |
object DoProduction(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Producer: IProducer | |
{ | |
public object DoProduction() | |
{ | |
return new object(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment