using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp16
{
public class Item
{
public string name { get; set; }
}
internal class App
{
//생성자
public App()
{
ItemFactory factory = new ItemFactory();
Console.WriteLine();
factory.CreateItem((item) =>
{
Console.WriteLine("{0}이 생성되었습니다.", item.name);
});
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp16
{
internal class ItemFactory
{
public ItemFactory() {
Console.WriteLine("ItemFactory 생성");
}
public void CreateItem(Action<Item> action)
{
Item item = new Item { name = "아이템" };
action(item);
}
}
}
반응형
'KDT > C# 프로그래밍' 카테고리의 다른 글
몬스터 잡고 아이템 드롭 후 아이템 가방에 넣기 (0) | 2023.07.28 |
---|---|
아이템 정보 저장하기 (0) | 2023.07.27 |
대리자 연습(2) (0) | 2023.07.27 |
대리자 연습(1) (0) | 2023.07.27 |
싱글톤 패턴으로 대리자 호출하기(2) (0) | 2023.07.27 |