static void Main(string[] args) { FruitFactory fruitFactory = new FruitFactory(); IFruit lemon = fruitFactory.CreateFruit(FruitType.Lemon); Console.WriteLine(lemon.Taste); }
public void Start() { Console.Write("Fruit salad with "); // Interface marker foreach (Type type in Assembly.GetExecutingAssembly().GetTypes() .Where(c => c.GetInterfaces().Contains(typeof(IFruit)))) { IFruit fruit = (IFruit)Activator.CreateInstance(type); //Create new instance of specific fruit Console.Write(fruit.GetType().Name.Split('.').Last() + ", "); } Console.WriteLine(); Console.Write("Salad with "); // Attribute marker foreach (Type type in Assembly.GetExecutingAssembly().GetTypes()) { if (type.GetCustomAttributes(typeof(Vegetable), true).Length > 0) { object vegetable = Activator.CreateInstance(type); //Create new instance of specific vegetable Console.Write(vegetable.GetType().Name.Split('.').Last() + ", "); } } Console.WriteLine(); }
public IFruitItem Create(IFruit fruit) { var name = ItemUtil.ProposeValidItemName(fruit.Title); using (new SecurityDisabler()) { using (new DatabaseSwitcher(Database.GetDatabase("master"))) { var fruitItem = ItemFactory.Create<IFruitItem>(new Guid("{1C66BBD6-BA2F-424B-A32F-26244D4AECD3}"), name); if (fruitItem != null) { fruitItem.Title.RawValue = fruit.Title; fruitItem.Colour.RawValue =fruit.Colour; fruitItem.Body.RawValue = fruit.Description; fruitItem.Save(); fruitItem.Publish(); return fruitItem; } } } return null; }
static void Main(string[] args) { var fruitFactory = new FruitFactory(); FruitType fruitType = AcquireFruit(); IFruit fruit = fruitFactory.GetInstance(fruitType); fruit.Prepare(); fruit.Eat(); }
/// <summary> /// 用于演示一个水果的三个过程. /// </summary> /// <param name="fruit"></param> private static void Demo(IFruit fruit) { // 种植. fruit.Plant(); // 成长. fruit.Grow(); // 收获. fruit.Harvest(); }
void Start() { //Elementos hijo del grid Food foreach (Transform t in foodGrid) { IFruit generatedFruit = eFactory.GetFruit((FruitTypes)generateRandomType()); fruits.Add(generatedFruit); generatedFruit.setSprite(t.gameObject); } }
static void Main(string[] args) { AbstractFactory abstractFactory = new LemonFactory(); IFruit lemon = abstractFactory.CreateInstance("sour", "yellow", 1.23); Console.WriteLine(lemon.Price); IFruit banana = abstractFactory.CreateInstance("sweet", "yellow", 2.87); Console.WriteLine(banana.Price); }
static void Main(string[] args) { IFruit fruit1 = FruitGardener.Factory("apple"); IFruit fruit2 = FruitGardener.Factory("Grape"); IFruit fruit3 = FruitGardener.Factory("Strawberry"); Demo(fruit1); Demo(fruit2); Demo(fruit3); Console.ReadLine(); }
/// <summary> /// 这里为 模拟的 客户端的 消费代码. /// /// 客户端 对于 不同体系的产品。 /// 消费代码是一样的。 /// </summary> /// <param name="gardener"></param> private static void Demo(IGardener gardener) { IFruit fruit = gardener.CreateFruit(); fruit.Plant(); fruit.Grow(); fruit.Harvest(); IVeggie veggie = gardener.CreateVeggie(); veggie.Plant(); }
static void Main(string[] args) { //设计模式: 简单工厂 //功能:根据提供字符串不同,得到某一个接口的特定实例,并进行一些自动化处理 //*这个模式不属于GoF23中的设计模式 IFruit fruit = FruitFactory.CreateFruit("Apple"); IFruit fruit2 = FruitFactory.CreateFruit("Banana"); Console.WriteLine($"fruit的信息是:{fruit.Info()}"); Console.WriteLine($"fruit2的信息是:{fruit2.Info()}"); Console.ReadLine(); }
private void FrmTest_Load(object sender, EventArgs e) { Book book = new Book() { Id = Guid.NewGuid(), AddTime = DateTime.Now, BookName = "aaa" }; TT <Book> .GetPropery(book); IFruit f = FruitFactory <Apple> .CreateFriut(); f.output(); }
static void Main(string[] args) { IFruitGardener[] fruitGardeners = new IFruitGardener[3]; fruitGardeners[0] = new AppleGardener(); fruitGardeners[1] = new GrapeGardener(); fruitGardeners[2] = new StrawberryFruitGardener(); foreach (IFruitGardener fruitGardener in fruitGardeners) { IFruit fruit = fruitGardener.Factory(); Demo(fruit); } Console.ReadLine(); }
public void Eat(IFruit fruit) { if (fruit == null) { throw new ArgumentNullException(); } if (fruit.StatAttribute == StatAttribute.Speed) { this.Speed += fruit.AttributePoints; } else if (fruit.StatAttribute == StatAttribute.Power) { this.Power += fruit.AttributePoints; } }
public Game( IMediator mediator, IFruit fruit, IStatusPanel statusPanel, IScorePanel scorePanel, IGameSoundPlayer gameSoundPlayer, IHumanInterfaceParser input, IPacMan pacman) { _mediator = mediator; _fruit = fruit; _statusPanel = statusPanel; _scorePanel = scorePanel; _gameSoundPlayer = gameSoundPlayer; _input = input; _pacman = pacman; }
public DemoAct( IMediator mediator, IFruit fruit, IMaze maze, IPacMan pacman, IGhostCollection ghostCollection, IHumanInterfaceParser input, IGameStats gameStats) { _mediator = mediator; _fruit = fruit; _maze = maze; _pacman = pacman; _ghostCollection = ghostCollection; _input = input; _gameStats = gameStats; }
public Handler(IGhostCollection ghostCollection, IFruit fruit, IMaze maze, IPacMan pacman, IGame game, IActs acts, IGameStats gameStats, IHaveTheMazeCanvases mazeCanvases) { _mazeCanvases = mazeCanvases; _ghostCollection = ghostCollection; _fruit = fruit; _maze = maze; _pacman = pacman; _game = game; _acts = acts; _gameStats = gameStats; }
static void Main(string[] args) { // 苹果 IFruit l_apple = Factory.Create("apple"); l_apple.IntroduceOneSelf(); // 橘子 IFruit l_orange = Factory.Create("orange"); l_orange.IntroduceOneSelf(); // 香蕉 IFruit l_banana = Factory.Create("banana"); l_banana.IntroduceOneSelf(); Console.ReadKey(); }
public static IFruit CreateFriut() { //var a = Activator.CreateInstance<TFruit>(); //return a; var ass = Assembly.GetExecutingAssembly(); var types = ass.GetTypes();//.Where(b=>b.GetType()==typeof(TFruit)).ToList(); IFruit aa = null; var types1 = ass.GetTypes().Where(type => type.BaseType != null && type.BaseType.IsGenericType && type.BaseType.GetGenericTypeDefinition() == typeof(TFruit)); foreach (var item in types) { if (item == typeof(TFruit)) { aa = Activator.CreateInstance(item) as IFruit; } } return(aa); }
public void SpawnFruit(ProduceRequirements requirements) { factory = FactoryProducer.GetFactory(FactoryType.Fruit); if (requirements.green) // If it is a green fruit, spawn an avocado { GameObject produce = Instantiate(avocadoPrefab); outputText.text = "Created an avocado."; m_Avocado = factory.GetFruit(FruitType.Avocado); m_Avocado.Fruitify(); } else if (requirements.yellow) // if it is a yellow fruit, spawn a banana { GameObject produce = Instantiate(bananaPrefab); outputText.text = "Created a banana."; m_Banana = factory.GetFruit(FruitType.Banana); m_Banana.Fruitify(); } else if (requirements == null) // if no requirements are given, spawn all fruits // This is for the case when the user presses the fruit key { m_Apple = factory.GetFruit(FruitType.Apple); m_Banana = factory.GetFruit(FruitType.Banana); m_Avocado = factory.GetFruit(FruitType.Avocado); m_Apple.Fruitify(); m_Banana.Fruitify(); m_Avocado.Fruitify(); } else // Otherwise spawn an apple { GameObject produce = Instantiate(applePrefab); outputText.text = "Created an apple."; m_Apple = factory.GetFruit(FruitType.Apple); m_Apple.Fruitify(); } }
internal void AddFruit(IFruit fruit) { IDomainEvent ev; if (fruit is Apple) { ev = new AppleAddedEvent(fruit.Id, fruit.Weight, fruit.FruitCondition); } else if (fruit is Pear) { ev = new PearAddedEvent(fruit.Id, fruit.Weight, fruit.FruitCondition); } else { ev = new UnknownFruitAddedEvent(fruit.Id, fruit.Weight, fruit.FruitCondition); } _events.Add(ev); Apply((dynamic)ev); }
public GameAct( ICoinBox coinBox, IMediator mediator, IHumanInterfaceParser input, IGameSoundPlayer gameSoundPlayer, IGameStats gameStats, IGhostCollection ghostCollection, IMaze maze, IPacMan pacman, IFruit fruit) { _coinBox = coinBox; _mediator = mediator; _input = input; _gameSoundPlayer = gameSoundPlayer; _gameStats = gameStats; _ghostCollection = ghostCollection; _maze = maze; _pacman = pacman; _fruit = fruit; }
/// <summary> /// Calcola il prezzo totale del frutto specificato della lista /// </summary> /// <param name="element">cosa</param> /// <param name="list">dove</param> /// <returns></returns> public static double GetRelativeCost(IFruit element, List <IFruit> list) { int reps = 0; // corrisponde al prezzo del frutto if (!list.Contains(element)) { throw new Exception("Elemento non presente nella lista"); } else { foreach (var item in list) { // se l'elemento cercato corrisponde a quello nella lista che guardo // ora allora incremento reps (= volte che il frutto è presente nella lista) if (item.GetName().Equals(element.GetName())) { reps++; } } return(GetFruitCost(element, reps)); } }
void Update() { // Get active object from ObjectManager, this is the object under the lazer pointer activeObject = this.GetComponent <ObjectManager>().isActive[1]; // if browesing then idle UI should be at the wall and all Fruit screens should be in storage if (_StateManager.currentUserState == StateManager.UserState.browesing) { if (_ObjectState.CanGrabOffShelf(activeObject)) { //idleUI.transform.position = uiStorage; //activeObject.GetComponent < IFruit > ().ScreenDisplay(inFront); } else { idleUI.transform.position = wall; if (IFruit.displayedScreenUI != null) { IFruit.TurnScreenOff(uiStorage); } } } // if examining then the idle UI should be in storage and the Fruit screen of the held object should be displayed else if (_StateManager.currentUserState == StateManager.UserState.examining) { _ObjectManager.heldObject.GetComponent <IFruit>().ScreenDisplay(inFront, screenRotation); //idleUI.transform.position = uiStorage; // Enable to hide screen UI when examining a fruit } else if (_StateManager.currentUserState == StateManager.UserState.busy) { } }
private string GetFruitName(IFruit fruit) // Interfaces CAN be used as Types { return($"This fruit is called: {fruit.Name}."); }
private string GetFruitName(IFruit fruit) { return($"This friut is called {fruit.Name}."); }
public string GetFruitName(IFruit fruit) { return fruit.Name; }
private string GetFruitName(IFruit fruit) => $"This fruit is called {fruit.Name}"; //style without {} from quiz I did not know about
private string GetFruitName(IFruit fruits) { return($"This fruit is called {fruits.Name}"); }
public void IFruitEvent(IFruit args) => this.ServerIFruitEventRaised?.Invoke(args);
public Eater(IFruit food) { Food = food; }
public Gorilla(IFruit fruit) { this.Fruit = fruit; }