Skip to content

Instantly share code, notes, and snippets.

@oinant

oinant/BasicFactory.cs

Last active Aug 29, 2015
Embed
What would you like to do?
using System;
namespace Oinant.Blog.Factory.SimpleExemple
{
public class MyBusinessObject
{
private string _content;
private DateTime _dateTimeReleventToBusinessLogic;
public MyBusinessObject(Tuple<DateTime, String> creationData)
{
_content = creationData.Item2;
_dateTimeReleventToBusinessLogic = creationData.Item1;
}
public bool IsBusinessRequirementMet()
{
return !string.IsNullOrEmpty(_content);
}
public void PerformBusinessLogic()
{
}
public string GetContent()
{
return _content;
}
}
class MyBusinessObjectFactory
{
private readonly IBusinessRepository _businessRepository;
public MyBusinessObjectFactory(IBusinessRepository businessRepository)
{
_businessRepository = businessRepository;
}
public MyBusinessObject Create(Guid id)
{
var content = _businessRepository.GetContent(id);
return new MyBusinessObject(new Tuple<DateTime, string>(DateTime.Now, content));
}
}
public class Client
{
private void Run()
{
var factory = new MyBusinessObjectFactory(new DummyBusinessRepository());
var myRunnerId = new Guid();
MyBusinessObject myObject = factory.Create(myRunnerId);
if(myObject.IsBusinessRequirementMet())
myObject.PerformBusinessLogic();
}
}
public interface IBusinessRepository
{
string GetContent(Guid id);
}
public class DummyBusinessRepository : IBusinessRepository
{
public string GetContent(Guid id)
{
return id.ToString();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.