Skip to content

Instantly share code, notes, and snippets.

@zharro
zharro / ApplicationService.cs
Created December 29, 2016 12:53
Separation of immutable core (ClearingManager) and mutable shell (ApplicationService and Persister)
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace ImmutableClearing
{
class ApplicationService
{
private readonly string _directoryName;
private readonly Persister _persister;
@zharro
zharro / CustomerService.cs
Last active December 27, 2016 16:11
Functions composition vs temporal coupling
public class CustomerService
{
public void Process(string customerName, string addressString)
{
Address address = CreateAddress(addressString);
Customer customer = CreateCustomer(customerName, address);
SaveCustomer(customer);
}
private Address CreateAddress(string addressString)
{
@zharro
zharro / Appointment.cs
Last active December 19, 2016 15:09
Entity simple example and base class. Base class comes from @vkhorikov (https://github.com/vkhorikov/DddInAction/tree/master/DddInPractice.Logic/Common).
using System;
class Appointment : Entity
{
public string Title { get; set; }
public int PatientId { get; set; }
public int RoomId { get; private set; }
public int? DoctorId { get; set; }
public bool IsConfirmed { get; private set; }
// Value object
@zharro
zharro / DateTimeRange.cs
Last active April 22, 2018 05:13
Value object simple example and base class. Base class comes from @vkhorikov (https://github.com/vkhorikov/DddInAction/tree/master/DddInPractice.Logic/Common)
using System;
class DateTimeRange : ValueObject<DateTimeRange>
{
public DateTime Start { get; }
public DateTime End { get; }
public DateTimeRange(DateTime start, DateTime end)
{
Start = start;
@zharro
zharro / FileSystemAgent.cs
Last active July 29, 2016 11:49
Interacting with file system
/// <summary>
/// Agent for interacting with file system
/// </summary>
public class FileSystemAgent : IFileSystemAgent
{
public IList<string> ReadAllLines(string fileName)
{
if (!File.Exists(fileName))
{
throw new ArgumentException($"File {fileName} doesn't exist");
@zharro
zharro / ComparerFactory.cs
Created January 19, 2016 14:46
Factory class for creating instances of IComparer (из книги Сергея Теплякова "Паттерны проектирования на платформе .NET")
using System;
using System.Collections.Generic;
namespace zharro.gists
{
class ComparerFactory
{
public static IComparer<T> Create<T>(Comparison<T> comparer)
{
return new DelegateComparer<T>(comparer);