This file contains 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
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