−using System;
using System.Collections.Generic;
using System.Linq;
var night = new MovieNight(new Screen(), new Lights(), new Player());
Console.WriteLine(night.Start("Moon"));
sealed class Screen
{
public string Lower() => "screen down";
public string Raise() => "screen up";
}
sealed class Lights
{
public string Dim() => "lights dim";
public string Restore() => "lights normal";
}
sealed class Player
{
public string Play(string title) => "play " + title;
public string Stop() => "player stop";
}
sealed class MovieNight(Screen screen, Lights lights, Player player)
{
public string Start(string title) =>
string.Join(" -> ", screen.Lower(), lights.Dim(), player.Play(title));
public string Stop() =>
string.Join(" -> ", player.Stop(), lights.Restore(), screen.Raise());
}
+using System;
using System.Collections.Generic;
using System.Linq;
var night = new MovieNight(new Screen(), new Lights(), new Player());
Console.WriteLine(night.Start("Moon"));
// 장치 하나의 동작과 여러 장치를 조정하는 순서를 구별한다.
sealed class Screen
{
public string Lower() => "screen down";
public string Raise() => "screen up";
}
sealed class Lights
{
public string Dim() => "lights dim";
public string Restore() => "lights normal";
}
sealed class Player
{
public string Play(string title) => "play " + title;
public string Stop() => "player stop";
}
// 호출부가 여러 장치와 순서를 외우지 않도록 준비 절차를 한곳에 둔다.
sealed class MovieNight(Screen screen, Lights lights, Player player)
{
public string Start(string title) =>
string.Join(" -> ", screen.Lower(), lights.Dim(), player.Play(title));
public string Stop() =>
string.Join(" -> ", player.Stop(), lights.Restore(), screen.Raise());
}