Skip to content

Instantly share code, notes, and snippets.

@oinant
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oinant/4ca495386bec0fa96f22 to your computer and use it in GitHub Desktop.
Save oinant/4ca495386bec0fa96f22 to your computer and use it in GitHub Desktop.
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