public void Should_Pass_If_Can_Calculate_Compact_Car_Price_Correctly()
        {
            // arrange
            CompactCar car = new CompactCar();

            // act
            var price = car.GetPrice();

            // assert
            Assert.Equal(100_000_000, price);
        }
Example #2
0
        static void Main(string[] args)
        {
            Car thecar = new CompactCar();

            thecar = new Navigation(thecar);
            thecar = new LeatherSeats(thecar);
            thecar = new Sunroof(thecar);

            Console.WriteLine(thecar.GetDescription());
            Console.WriteLine(thecar.GetPrice());
        }
Example #3
0
        static void Main(string[] args)
        {
            Car theCar = new CompactCar();

            theCar = new LeatherSeat(theCar);
            theCar = new AllWheelDrive(theCar);
            theCar = new Navigation(theCar);

            Console.WriteLine(theCar.getDescription());
            Console.WriteLine($"{theCar.getPrice():C2}");
        }
        public void Should_Pass_If_Can_Calculate_Compact_Car_Price_With_Navigation_Correctly()
        {
            // arrange
            CompactCar car        = new CompactCar();
            Navigation navigation = new Navigation(car);

            // act
            var price = navigation.GetPrice();

            // assert
            Assert.Equal(100_500_000, price);
        }
        public void Should_Pass_If_Can_Calculate_Compact_Car_Price_With_Navigation_And_SunRoof_Correctly()
        {
            // arrange
            CompactCar car        = new CompactCar();
            Navigation navigation = new Navigation(car);
            SunRoof    sunRoof    = new SunRoof(navigation);

            // act
            var price = sunRoof.GetPrice();

            // assert
            Assert.Equal(103_300_000, price);
        }
        public static List <CompactCar> InitializeGarage()
        {
            List <CompactCar> garage = new List <CompactCar>();

            CompactCar a1 = new CompactCar();

            a1.Make          = "Audi";
            a1.Model         = "A1";
            a1.Year          = 2018;
            a1.Doors         = 2;
            a1.NCAPCompliant = true;
            a1.Seats         = 4;
            a1.Features.Add(new Feature("ISOFIX", true));
            a1.Features.Add(new Feature("ABS", true));
            a1.Features.Add(new Feature("Laser Headlights", false));
            a1.Features.Add(new Feature("LED DRL", true));
            a1.Features.Add(new Feature("Assisted Driving", true));
            garage.Add(a1);

            CompactCar bal = new CompactCar();

            bal.Make          = "Suzuki";
            bal.Model         = "Baleno";
            bal.Year          = 2018;
            bal.Doors         = 4;
            bal.NCAPCompliant = true;
            bal.Seats         = 4;
            bal.Features.Add(new Feature("ISOFIX", true));
            bal.Features.Add(new Feature("ABS", true));
            bal.Features.Add(new Feature("Laser Headlights", false));
            bal.Features.Add(new Feature("LED DRL", true));
            bal.Features.Add(new Feature("Assisted Driving", false));
            garage.Add(bal);

            CompactCar up = new CompactCar();

            up.Make          = "Volkswagen";
            up.Model         = "Up";
            up.Year          = 2016;
            up.Doors         = 4;
            up.NCAPCompliant = true;
            up.Seats         = 4;
            up.Features.Add(new Feature("ISOFIX", true));
            up.Features.Add(new Feature("ABS", true));
            up.Features.Add(new Feature("Laser Headlights", false));
            up.Features.Add(new Feature("LED DRL", false));
            up.Features.Add(new Feature("Assisted Driving", false));
            garage.Add(up);

/*             SportsCar r8 = new SportsCar();
 *          r8.Make = "Audi";
 *          r8.Model = "R8";
 *          r8.Year = 2014;
 *          r8.Seats = 2;
 *          r8.HP = 493;
 *          r8.LaunchControl = false;
 *          r8.Turbo = true;
 *          r8.Features.Add(new Feature("Laser Headlights",false));
 *          r8.Features.Add(new Feature("LED DRL",true));
 *          r8.Features.Add(new Feature("Assisted Driving",false));
 *          r8.Features.Add(new Feature("Hard Roof",true));
 *          garage.Add(r8); */

            return(garage);
        }
 public static void PrintCarData(CompactCar car)
 {
     Console.WriteLine("Marca: {0} | Modelo: {1} | Año: {2} | Seats: {3}", car.Make, car.Model, car.Year, car.Seats);
     Console.WriteLine("Doors: {0} | Aprobación NCAP: {1}", car.Doors, car.NCAPCompliant);
 }
Example #8
0
        static void Main(string[] args)
        {
            #region Decorator - Using Composition to limit inheritance and simplify object relationships easier to maintain and manage.
            //Inside ConcreteDecorator any number of features can be added to the car and price for the car can be updated.
            Decorator.Component.Car sampleCar = new CompactCar();
            sampleCar = new LeatherSeats(sampleCar);
            Console.WriteLine(sampleCar.GetDescription());
            Console.WriteLine($"{sampleCar.GetCarPrice():C2}");
            #endregion

            #region Observer - Change in one object causes a change or action in another.
            var trump     = new Trump("I love my wife");
            var firstFan  = new Fan("Rohit");
            var secondFan = new Fan("Ram");
            trump.AddFollower(firstFan);
            trump.AddFollower(secondFan);
            trump.Tweet = "I hate media";
            #endregion

            #region Builder Pattern- Separate and reuse a specific process to build an object /use when constructing a complex object
            //Director- construct ()
            //Builder - Build part
            //CarBuilder to construct two types of cars
            //override the method of building a car in separate classes which derive from an abstract carbuilder
            //create a list of carbuilder objects to specify the current known types of cars that can be built
            //create a factory
            var superBuilder       = new SuperCarBuilder();
            var notSoSsuperBuilder = new NotSoSuperCarBuilder();

            var factory  = new CarFactory();
            var builders = new List <CarBuilder> {
                superBuilder, notSoSsuperBuilder
            };

            foreach (var b in builders)
            {
                var c = factory.Build(b);
                Console.WriteLine($"The car requested by " + $"{b.GetType().Name}:" + Environment.NewLine
                                  + $"Horse Power: {c.HorsePower}" + Environment.NewLine
                                  + $"Impressive feature: {c.MostImpressiveFeature}" + Environment.NewLine
                                  + $"Top speed: {c.TopSpeedMPH} mph" + Environment.NewLine);
            }
            #endregion

            #region Bridge Pattern- Used to separate an abstraction from its implementation so both can be modified independently
            //Sending messages from sms or service without each affecting the other
            IMessageSender text = new TextSender();
            IMessageSender web  = new WebServiceSender();

            Message message = new SystemMessage(text);
            message.Subject       = "A message";
            message.Body          = "hi there, please know this";
            message.MessageSender = text;
            message.Send();

            message.MessageSender = web;
            message.Send();

            #endregion

            #region Chain of responsibility- Chain the receiving objects and pass the request along the chain until an object handles it.
            //Avoid coupling the sender of a request to its receiver by giving more than one object a chance to handle the request
            Approver Bobby  = new Director();
            Approver Sunny  = new VicePresident();
            Approver Dharam = new President();

            Bobby.SetSuccessor(Sunny);
            Sunny.SetSuccessor(Dharam);

            Purchase P = new Purchase()
            {
                Amount = 10000, Number = 1
            };
            Bobby.ProcessRequest(P);


            #endregion

            #region Command - Wrap request as an object to be implemented later or invoke at different points in time.
            //Encapsulate a request as an object, thereby letting you parameterize clients with different requests -queue or log  and support undoable operations
            //Use an object to store required information to perform an action at any point in time.
            var user = new User();
            user.Compute('+', 100);
            user.Compute('-', 50);
            user.Compute('*', 10);
            user.Compute('/', 2);

            //undo
            user.Undo(4);

            //Redo
            user.Redo(3);
            #endregion
            Console.ReadLine();
        }