public static void Main(string[] args) { FactoryProducer producer = new FactoryProducer(); // producing set of red widgets AbstractShapeFactory redFactory = producer.GetFactory("Red"); IShape shape1 = redFactory.GetShape("CIRCLE"); IShape shape2 = redFactory.GetShape("RECTANGLE"); IShape shape3 = redFactory.GetShape("SQUARE"); shape1.draw(); shape2.draw(); shape3.draw(); // producing set of green widgets AbstractShapeFactory greenFactory = producer.GetFactory("Green"); IShape shape4 = greenFactory.GetShape("CIRCLE"); IShape shape5 = greenFactory.GetShape("RECTANGLE"); IShape shape6 = greenFactory.GetShape("SQUARE"); shape4.draw(); shape5.draw(); shape6.draw(); // producing set of blue widgets AbstractShapeFactory blueFactory = producer.GetFactory("Blue"); IShape shape7 = blueFactory.GetShape("CIRCLE"); IShape shape8 = blueFactory.GetShape("RECTANGLE"); IShape shape9 = blueFactory.GetShape("SQUARE"); shape7.draw(); shape8.draw(); shape9.draw(); }
public Verdict RunTest() { //create factory based on the file extension var factory = FactoryProducer.GetFactory(Path.GetExtension(_inputFilePath)); //construct transformer and apply transformations var transformer = factory.CreateTransformer(); WriteLine($"Starting transformation of {_inputFilePath}"); var transformations = transformer.Transform(InputFileContent, Policy); if (!ValidateTransformations(transformations)) { var errorVerdict = new Verdict(); errorVerdict.TransformationResult = transformations; return(errorVerdict); } WriteLine($"Transformation completed. Generated {transformations.CodeTransformations.Count} code versions."); //persist transformed code if (_saveTransformations) { transformations.SaveTransformations(_inputFilePath); WriteLine($"Saved the transformed code versions to {Path.GetDirectoryName(_inputFilePath)}"); } //construct scheduler and schedule the code for execution WriteLine($"Starting scheduler."); var scheduler = factory.CreateScheduler(); try { scheduler.Schedule(transformations.CodeTransformations, _arguments); } catch (Exception ex) { var errorVerdict = new Verdict(); transformations.Errors.Add(ex.ToString()); errorVerdict.TransformationResult = transformations; return(errorVerdict); } WriteLine($"Scheduler completed."); //determine verdict after execution return(scheduler.GetVerdict(transformations.OutputChannels)); }
public void SpawnAnimals() { factory = FactoryProducer.GetFactory(FactoryType.Animal); if (!(env.time.text == "9:00 AM") && (env.isRaining == false)) { m_Cat = factory.GetAnimal(AnimalType.Cat); m_Cat.Voice(); GameObject catInstance = Instantiate(Resources.Load("Cat", typeof(GameObject))) as GameObject; catInstance.transform.position = new Vector3((Random.Range(-10f, 10f)), 0, 0); } else { m_Dog = factory.GetAnimal(AnimalType.Dog); m_Dog.Voice(); GameObject dogInstance = Instantiate(Resources.Load("Dog", typeof(GameObject))) as GameObject; dogInstance.transform.position = new Vector3((Random.Range(-10f, 10f)), 0, 0); } }
static void Main(string[] args) { //获取形状工厂 AbstractFactory shapeFactory = FactoryProducer.GetFactory("SHAPE"); //获取形状为 Circle 的对象 IShape shape1 = shapeFactory.GetShape("CIRCLE"); //调用 Circle 的 Draw 方法 shape1.Draw(); //获取形状为 Rectangle 的对象 IShape shape2 = shapeFactory.GetShape("RECTANGLE"); //调用 Rectangle 的 Draw 方法 shape2.Draw(); //获取形状为 Square 的对象 IShape shape3 = shapeFactory.GetShape("SQUARE"); //调用 Square 的 Draw 方法 shape3.Draw(); //获取颜色工厂 AbstractFactory colorFactory = FactoryProducer.GetFactory("COLOR"); //获取颜色为 Red 的对象 IColor color1 = colorFactory.GetColor("RED"); //调用 Red 的 Fill 方法 color1.Fill(); //获取颜色为 Green 的对象 IColor color2 = colorFactory.GetColor("GREEN"); //调用 Green 的 Fill 方法 color2.Fill(); //获取颜色为 Blue 的对象 IColor color3 = colorFactory.GetColor("BLUE"); //调用 Blue 的 Fill 方法 color3.Fill(); }
public void SpawnVeggies(ProduceRequirements requirements) { factory = FactoryProducer.GetFactory(FactoryType.Veggie); if (requirements.green) // If it's a green vegetable, spawn Broccoli { GameObject produce = Instantiate(broccoliPrefab); outputText.text = "Created broccoli."; m_Broccoli = factory.GetVeggie(VeggieType.Broccoli); m_Broccoli.Vegetate(); } else if (requirements.yellow) // If it's a yellow vegetable, spawn a Potato { GameObject produce = Instantiate(potatoPrefab); outputText.text = "Created a potato."; m_Potato = factory.GetVeggie(VeggieType.Potato); m_Potato.Vegetate(); } else if (requirements == null) // if no requirements are given, spawn all vegetables //This is the case for when the user presses the vegetable key { m_Carrot = factory.GetVeggie(VeggieType.Carrot); m_Broccoli = factory.GetVeggie(VeggieType.Broccoli); m_Potato = factory.GetVeggie(VeggieType.Potato); m_Carrot.Vegetate(); m_Broccoli.Vegetate(); m_Potato.Vegetate(); } else // Otherwise spawn a carrot { GameObject produce = Instantiate(carrotPrefab); outputText.text = "Created a carrot."; m_Carrot = factory.GetVeggie(VeggieType.Carrot); m_Carrot.Vegetate(); } }
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(); } }
private void SpawnDestructible() { AbstractFactory destrFactory = FactoryProducer.GetFactory("Destructible"); List <Sprite> destructables = new List <Sprite>(); Sprite healthCrateObj = destrFactory.GetDestructible("HealthCrate").SpawnObject(); Sprite itemCrateObj = destrFactory.GetDestructible("ItemCrate").SpawnObject(); destructables.Add(healthCrateObj); destructables.Add(itemCrateObj); foreach (Sprite destructable in destructables) { bool isSpawned = ForceSpawnObject(destructable); if (isSpawned) { GameState.Collidables.Add(destructable); } } }
public ActionResult Login(LoginViewModel user, string ReturnUrl) { log.Info("Login in functionality of the application."); try { if (ModelState.IsValid) { //validation using Abstract design pattern AbstractFactory abstractfactory = FactoryProducer.GetFactory("IUserValidation"); IUserValidation userValidation = abstractfactory.getuservalidation("UserValidation"); //UserValidation userValidation = new UserValidation(); // validating user credentials UserAccount userAccount = null; if (userValidation.ValidateUser(user?.Email, user?.Password, out userAccount)) { FormsAuthentication.SetAuthCookie(userAccount.GetUserName(), user.RememberMe); if (ReturnUrl != null && !string.IsNullOrWhiteSpace(ReturnUrl)) { return(Redirect(ReturnUrl)); } else { return(RedirectToAction(ProjectConstants.Index, ProjectConstants.Dashboard, null)); } } else { ModelState.AddModelError(string.Empty, ProjectConstants.InvalidLoginMsg); log.Info("Login failed for the application."); } } } catch (Exception) { throw; } return(View()); }
static void Main(string[] args) { AbstractFactory factory = FactoryProducer.GetFactory("shape"); IShape shape = factory.GetShape("square"); shape.Draw(); shape = factory.GetShape("rectangle"); shape.Draw(); shape = factory.GetShape("circle"); shape.Draw(); Console.WriteLine(); factory = FactoryProducer.GetFactory("color"); IColor color = factory.GetColor("Red"); color.FillColor(); color = factory.GetColor("Green"); color.FillColor(); color = factory.GetColor("Blue"); color.FillColor(); Console.WriteLine(); }
public void Run() { System.Console.WriteLine("I am Abstract Faction Pattern"); AbstractFactory shapeFactory = FactoryProducer.GetFactory("Shape"); IShape shape = shapeFactory.GetShape("Circle"); shape.Draw(); shape = shapeFactory.GetShape("Rectangle"); shape.Draw(); shape = shapeFactory.GetShape("Square"); shape.Draw(); AbstractFactory colorFactory = FactoryProducer.GetFactory("Color"); IColor color = colorFactory.GetColor("Red"); color.Fill(); color = colorFactory.GetColor("Green"); color.Fill(); color = colorFactory.GetColor("Blue"); color.Fill(); }
public IGameStateConfigurator AddImpassableShape(Func <AbstractFactory, BaseShape> action) { if (!mapInitialized) { throw new Exception("Map uninitialized"); } var shapeFactory = FactoryProducer.GetFactory(passable: false); var shape = action(shapeFactory); if (shape is ImpassablePlatform) { Platforms.Add(shape); } gameState.Platforms.AddShape(shape); Logging.Instance.Write("[GameStateBuilder] Add impassable shape", LoggingLevel.Pattern); return(this); }
private static void Main() { var shapeFactory = FactoryProducer.GetFactory(false); var shape1 = shapeFactory.GetShape(ShapesEnum.Rectangle); shape1.Draw(); var shape2 = shapeFactory.GetShape(ShapesEnum.Square); shape2.Draw(); shapeFactory = FactoryProducer.GetFactory(true); var shape3 = shapeFactory.GetShape(ShapesEnum.Rectangle); shape3.Draw(); var shape4 = shapeFactory.GetShape(ShapesEnum.Square); shape4.Draw(); }
public ActionResult AddMember(LibMember newmember) { if (ModelState.IsValid) { //MemberValidation membervalidation = new MemberValidation(); AbstractFactory abstractfactory = FactoryProducer.GetFactory("IMemberValidation"); IMemberValidation membervalidation = abstractfactory.getmembervalidation("MemberValidation"); if (membervalidation.ValidateMember(newmember)) { MemberTable memberTable = new MemberTable(db); memberTable.Insert(newmember); ModelState.Clear(); ViewBag.Message = newmember.Firstname + ProjectConstants.SuccessMsg; } else { ViewBag.Message1 = ProjectConstants.MemberExistingMsg; } } return(View(ProjectConstants.AddMember)); }
private void Factory() { AbstractFactory factory = FactoryProducer.GetFactory(false); IShape shape1 = factory.GetShape("RECTANGLE"); shape1.Draw(); IShape shape2 = factory.GetShape("SQUARE"); shape2.Draw(); AbstractFactory roundedFactory = FactoryProducer.GetFactory(true); IShape shape3 = roundedFactory.GetShape("RECTANGLE"); shape3.Draw(); IShape shape4 = roundedFactory.GetShape("SQUARE"); shape4.Draw(); }
public ActionResult AddBook(Book newbook) { try { if (ModelState.IsValid) { // BookValidation bookValidation = new BookValidation(); // validating whether the book already exists or not // Abstract Factory pattern AbstractFactory abstractfactory = FactoryProducer.GetFactory("IBookValidation"); IBookValidation bookValidation = abstractfactory.getbookvalidation("BookValidation"); if (bookValidation.ValidateBook(newbook)) { int id = newbook.BookID; BookTable booktable = new BookTable(db); newbook.Status = BookStatus.Available.ToString(); booktable.Insert(newbook); ModelState.Clear(); ViewBag.Message = newbook.Name + ProjectConstants.SuccessMsg; } else { ViewBag.Message = ProjectConstants.AddBookFailMsg; return(View(ProjectConstants.AddBook)); } return(View(ProjectConstants.AddBook)); } } catch (Exception) { log.Error("Error while adding book to the database"); throw; } return(View(ProjectConstants.AddBook)); }
static void Main(string[] args) { //get normal shape factory AbstractFactory shapeFactory = FactoryProducer.GetFactory(false); Shape normalSquare = shapeFactory.GetShape(ShapeType.Square); normalSquare.Draw(); Shape normalRectangle = shapeFactory.GetShape(ShapeType.Rectangle); normalRectangle.Draw(); //get rounded shape factory AbstractFactory roundedShapeFactory = FactoryProducer.GetFactory(true); Shape roundedSquare = roundedShapeFactory.GetShape(ShapeType.Square); roundedSquare.Draw(); Shape roundedRectangle = roundedShapeFactory.GetShape(ShapeType.Rectangle); roundedRectangle.Draw(); }
public static void TestPrototype() { AbstractFactory abstractShapeFactory = FactoryProducer.GetFactory(true); BaseShape shape = abstractShapeFactory.CreateEntityShape(Shape.HealthCrystal, 2, 5); BaseShape shallow = shape.Clone(); // Shallow Copy BaseShape deep = shape.DeepCopy(); // Deep Copy ShapeBlock ba = shape.GetShapes().First(); ShapeBlock sh = shallow.GetShapes().First(); ShapeBlock de = deep.GetShapes().First(); Logging.Instance.Write("Before"); Logging.Instance.Write("Base: " + shape.GetShapes().GetHashCode().ToString() + "(OffsetX: " + ba.OffsetX + ")"); Logging.Instance.Write("Shallow: " + shallow.GetShapes().GetHashCode().ToString() + " (OffsetX: " + sh.OffsetX + ")"); Logging.Instance.Write("Deep: " + deep.GetShapes().GetHashCode().ToString() + " (OffsetX: " + de.OffsetX + ")"); ba.OffsetX = 10; Logging.Instance.Write("After"); Logging.Instance.Write("Base: " + shape.GetShapes().GetHashCode().ToString() + " (OffsetX: " + ba.OffsetX + ")"); Logging.Instance.Write("Shallow: " + shallow.GetShapes().GetHashCode().ToString() + " (OffsetX: " + sh.OffsetX + ")"); Logging.Instance.Write("Deep: " + deep.GetShapes().GetHashCode().ToString() + " (OffsetX: " + de.OffsetX + ")"); }
public static void Run() { var shapeFactory = FactoryProducer.GetFactory(FactoryProducer.ShapeFactory); var square = shapeFactory.GetShape(ShapeFactory.Square); square.draw(); var rectangle = shapeFactory.GetShape(ShapeFactory.Rectangle); rectangle.draw(); var circle = shapeFactory.GetShape(ShapeFactory.CirCle); circle.draw(); var colorFactory = FactoryProducer.GetFactory(FactoryProducer.ColorFactory); var red = colorFactory.GetColor(ColorFactory.Red); red.fill(); var green = colorFactory.GetColor(ColorFactory.Green); green.fill(); var blue = colorFactory.GetColor(ColorFactory.Blue); blue.fill(); }
public static void TestAbstractFactory() { AbstractFactory abstractShapeFactory = FactoryProducer.GetFactory(true); BaseShape shape = abstractShapeFactory.CreateEntityShape(Shape.HealthCrystal, 20, 5); }
public void SpawnMargherita() { factory = FactoryProducer.GetFactory(FactoryType.Pizza); m_Margherita = factory.GetPizza(ToppingType.Margherita); Debug.Log("Price: " + m_Margherita.GetPrice()); }
public void SpawnBBQChicken() { factory = FactoryProducer.GetFactory(FactoryType.Pizza); m_BBQChicken = factory.GetPizza(ToppingType.BbqChicken); Debug.Log("Price: " + m_BBQChicken.GetPrice()); }
public void SpawnSupreme() { factory = FactoryProducer.GetFactory(FactoryType.Pizza); m_Supreme = factory.GetPizza(ToppingType.Supreme); Debug.Log("Price: " + m_Supreme.GetPrice()); }
public void SpawnPepperoni() { factory = FactoryProducer.GetFactory(FactoryType.Pizza); m_Pepperoni = factory.GetPizza(ToppingType.Pepperoni); Debug.Log("Price: " + m_Pepperoni.GetPrice()); }
public void SpawnCheesePizza() { factory = FactoryProducer.GetFactory(FactoryType.Pizza); m_Cheese = factory.GetPizza(ToppingType.Cheese); Debug.Log("Price: " + m_Cheese.GetPrice()); }
static void Main(string[] args) { Console.WriteLine("Singleton Pattern"); // Singleton Pattern SingleObject singleObject = SingleObject.Instance(); singleObject.ShowMessage(); Console.WriteLine("\nBuilder Pattern"); // Builder Pattern MealBuilder mealBuilder = new MealBuilder(); Meal vegMeal = mealBuilder.PrepareVegMeal(); Console.WriteLine("Veg Meal"); vegMeal.ShowItems(); Console.WriteLine("Total Cost : " + vegMeal.GetCost()); Meal nonVegMeal = mealBuilder.PrepareNonVegMeal(); Console.WriteLine("NonVeg Meal"); nonVegMeal.ShowItems(); Console.WriteLine("Total Cost : " + nonVegMeal.GetCost()); Console.WriteLine("\nAbstract Factory"); // Abstract Factory Pattern AbstractFactory shapeFactory = FactoryProducer.GetFactory("shape"); IShape circleShape = shapeFactory.GetShape("circle"); circleShape.Draw(); AbstractFactory colorFactory = FactoryProducer.GetFactory("color"); IColor blueColor = colorFactory.GetColor("blue"); blueColor.Fill(); Console.WriteLine("\nAdapter"); //Adapter Pattern AudioPlayer audioPlayer = new AudioPlayer(); audioPlayer.Play("mp4"); audioPlayer.Play("flac"); audioPlayer.Play("vlc"); Console.WriteLine("\nFacade"); //Facade Pattern ShapeMaker shapeMaker = new ShapeMaker(); shapeMaker.DrawCircle(); shapeMaker.DrawRectangle(); shapeMaker.DrawSquare(); Console.WriteLine("\nDecorator doesn't work"); //Decorator Pattern IDecoratorShape rectangle = new RectangleDecorator(); IDecoratorShape redRectangle = new RedShapeDecorator(new RectangleDecorator()); Console.WriteLine("Rectangle with no color"); rectangle.Draw(); Console.WriteLine("Rectangle with color"); redRectangle.Draw(); Console.WriteLine("\nComposite"); //Composite Pattern Employee DSI = new Employee("employee1", "DSI", 100000); Employee chefDeProjet1 = new Employee("employee2", "Chef de projet", 60000); Employee chefDeProjet2 = new Employee("employee3", "Chef de projet", 60000); Employee dev1 = new Employee("employee4", "Développeur", 40000); Employee dev2 = new Employee("employee5", "Développeur", 40000); DSI.Add(chefDeProjet1); DSI.Add(chefDeProjet2); chefDeProjet1.Add(dev1); chefDeProjet2.Add(dev2); Console.WriteLine(DSI.Details()); foreach (Employee e1 in DSI.GetSubordinates()) { Console.WriteLine(e1.Details()); foreach (Employee e2 in e1.GetSubordinates()) { Console.WriteLine(e2.Details()); } } Console.WriteLine("\nBridge"); //Bridge Pattern BridgeShape shape1 = new BridgeCircle(10, 10, 1, new GreenCircle()); BridgeShape shape2 = new BridgeCircle(100, 100, 10, new RedCircle()); shape1.Draw(); shape2.Draw(); Console.WriteLine("\nCommand"); //Command Pattern Stock stock1 = new Stock("laptop", 100); BuyStock buyStock = new BuyStock(stock1); Stock stock2 = new Stock("screen", 30); SellStock sellStock = new SellStock(stock2); Broker broker = new Broker(); broker.TakeOrder(buyStock); broker.TakeOrder(sellStock); broker.PlaceOrders(); Console.WriteLine("\nInterpreter"); //Interpreter Pattern IExpression isMale = InterpreterPatternDemo.GetMaleExpression(); IExpression isMarried = InterpreterPatternDemo.GetMarriedWomanExpression(); Console.WriteLine("John is male ? " + isMale.Interpret("john")); Console.WriteLine("Barbara is male ? " + isMale.Interpret("barbara")); Console.WriteLine("Julie is married ? " + isMarried.Interpret("julie married")); Console.WriteLine("Bob is married ? " + isMarried.Interpret("bob married")); }