C#

대리자 연습 3,4

송현호 2023. 7. 27. 15:05
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Starcraft
{
    internal class ItemFactory
    {
        //생성자
        public ItemFactory()
        {
        }

        public void CreateItem (Action<Item> callback)
        {
            Item item = new Item();
            callback(item);
        }
    }
}​
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.Eventing.Reader;

namespace Starcraft
{
    public class App
    {
        //생성자
        public App()
        {
            ItemFactory factory = new ItemFactory();

            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 Starcraft
{
    internal class Item
    {
        public string name;
        //생성자
        public Item()
        {
            this.name = "양념치킨";
        }
    }
}