Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Need to refractor this piece of shit

Name: OP hates his boss 2012-04-26 3:21

Been given this absolute piece of shit to attempt to refractor
-have i missed anything?

using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;

namespace Assignment1
{
    class Program
    {
        static void recieptHeader()
        {
            Console.WriteLine("\nAUTOMATED FUEL DELIVERY SYSTEM");
            Console.WriteLine("\nRECEIPT");
        }

        private static void RegisteredUsers(ArrayList registeredUsers)
        {
            registeredUsers.Add(new CommunicationSystem("476541", "Visa", 50));
            registeredUsers.Add(new CommunicationSystem("302354", "MasterCard", 400));
            registeredUsers.Add(new CommunicationSystem("470614", "Amex", 200));
            registeredUsers.Add(new CommunicationSystem("711251", "Diners", 90));
        }

        static void Main(string[] args)
        {
            SystemController aSystem = new SystemController();

            ArrayList registeredUsers = new ArrayList();

            // populate registered users
            RegisteredUsers(registeredUsers);

            aSystem.setRegisteredUsers(registeredUsers);


            // Add fuel to tank
            FuelTank aTank = aSystem.getFuelTank();
            aTank.addFuel(1000); // litres

            //validate transaction

            CardReader customer1 = aSystem.getCardReader();
            customer1.readCard("476541", "Visa");

            aSystem.getCardStatus(customer1);


            // Scenario 1 - Enter cash limit
            if (aSystem.getCardReader().getCardSatus() == SystemController.CardStatus_Valid)
            {
                Pump aPump = customer1.getPump();
                // Fuel selection
                aPump.setFuelType(SystemController.Unleaded);
                // set cash
                aPump.setPrice(40);      
                // check credit limit
                // check fuel price with customers selection
                if (customer1.getCreditLimit() > aPump.getPrice())
                {
                    double fuelDelivery = aPump.getPrice() / SystemController.UnleadedPrice;
                  
                    aPump.activate();
                    if (aTank.getTotalLevel() > fuelDelivery)
                    {
                        aPump.setFuelDispensed(fuelDelivery);
                    }
                    aPump.deactivate();
                    aTank.removeFuel(fuelDelivery);
                    customer1.setCreditLimit(customer1.getCreditLimit() - aPump.getPrice());
                    DateTime currTime = DateTime.Now;

                    // Print receipt
                    recieptHeader();
                    Console.WriteLine("\nDate : {0:d}", currTime);
                    Console.Write("\nPaid ${0} for {1:#.##} litres of ", aPump.getPrice(), fuelDelivery);
                    if (aPump.getFuelType() == SystemController.Unleaded)
                        Console.Write("Unleaded");
                    else if (aPump.getFuelType() == SystemController.PremiumUnleaded)
                        Console.Write("Premium Unleaded");
                    else if (aPump.getFuelType() == SystemController.LPG)
                        Console.Write("LPG");
                    else if (aPump.getFuelType() == SystemController.Diesel)
                        Console.Write("Diesel");
                    Console.WriteLine("\n\nPress any key to continue...");
                    string garbage = Console.ReadLine();
                    Console.Clear();
                  
                   
                }
         

                // max amount of fuel
                CardReader customer2 = new CardReader();
                customer2.readCard("302354", "MasterCard");
                aSystem.getCardStatus(customer2);

                // Scenario 2 - Customer enters max fuel
                if (aSystem.getCardReader().getCardSatus() == SystemController.CardStatus_Valid)
                {
                    // check fuel price with customers selection
                   
                    double maxDelivery = customer2.getCreditLimit() / SystemController.PremiumUnleadedPrice;
                    aSystem.setMaxDelivery(maxDelivery);
                    Pump bPump = customer2.getPump();
                    bPump.setFuelType(SystemController.PremiumUnleaded);
                    bPump.activate();
                    double fuelDispensed = 0;
                    double charge = 0;
                    bool filled = false;
                    Console.WriteLine("\n\nDISPENSING FUEL");
                    Console.WriteLine("\nPress y to start dispensing or ..\n\npress any other key to quit");
                    string a = Console.ReadLine().ToLower();
                    if (a.Equals("y"))
                    {
                        Console.Clear();
                        Console.WriteLine("\n\nDispensing fuel");
                        Console.WriteLine("\nPress <CR> to dispence in 0.1 litre increment\n\nPress q to terminate dispensing");
                        string req = Console.ReadLine().ToLower();
                        while ((aTank.getTotalLevel() >= maxDelivery) & (!req.Equals("q")) & fuelDispensed <= maxDelivery & customer2.getCreditLimit() >= charge)
                        {
                            filled = true;
                            charge += 0.1 * SystemController.PremiumUnleadedPrice;
                            fuelDispensed += 0.1;
                            aTank.removeFuel(0.1);
                                                      
                            Console.Clear();
                            Console.WriteLine("\n\nDispensing fuel");
                            Console.WriteLine("\nFuel dispensed {0:F2} litre(s) and Cost {1:C}", fuelDispensed, charge);
                            Console.WriteLine("\nPress <CR> to despence in 0.1 litre increment\n\nPress q to terminate dispensing");
                            string ch = Console.ReadLine().ToLower();
                            if (ch.Equals("q"))
                            {
                                bPump.setFuelDispensed(fuelDispensed);
                                bPump.setPrice(charge);
                                break;
                            }
                        }
                        if (filled)
                        {
                            customer2.setCreditLimit(customer2.getCreditLimit() - charge);
                            DateTime currTime = DateTime.Now;
                            // Print receipt
                            recieptHeader();
                            Console.WriteLine("\nDate : {0:d}", currTime);
                            Console.Write("\nPaid ${0} for {1:#.##} litres of ", bPump.getPrice(), bPump.getFuelDispensed());
                            if (bPump.getFuelType() == SystemController.Unleaded)
                                Console.Write("Unleaded");
                            else if (bPump.getFuelType() == SystemController.PremiumUnleaded)
                                Console.Write("Premium Unleaded");
                            else if (bPump.getFuelType() == SystemController.LPG)
                                Console.Write("LPG");
                            else if (bPump.getFuelType() == SystemController.Diesel)
                                Console.Write("Diesel");
                            Console.WriteLine("\n\nPress any key to continue...");
                            string garbage = Console.ReadLine().ToLower();
                            Console.Clear();

                        }
                    }                                       
                }
            }
        }
    }
}

Name: Anonymous 2012-04-26 7:34

>>5
Well, what happens if you decide you need to extend your system and you realise that you NOW do have to reuse method "A".
Then you refactor it.

and possibly a harder job because you've now built a system around this code
You couldn't have done that, since it was used in one place only, by definition.

A hallmark - if not the hallmark - of good object oriented design is that you can modify and extend a system by adding code rather than hacking it.... In short, change is additive, not invasive.
A hallmark - if not the hallmark - of the terminal OOP of the brain is the irrational, unsubstantiated and completely impenetrable delusion of prescience. In fact it's even funnier than that: afflicted don't merely believe that they can accurately predict future requirements, instead they believe that they can write code that could be easily extended to accommodate future requirements without having a slightest idea what those would be. Again and again they prove themselves wrong, but somehow interpret it as a sign that they have not tried hard enough, which only strengthens they conviction. Mind boggles.

Listen here, faggot. From my extensive experience with all kinds of legacy systems written by a variety of shitty coders in a variety of shitty styles I have come to believe that there's only one characteristic of code that helps predict how hard it would be to fix or extend it: its size. Making a change to functionality spanning 500 lines is ten times as hard as making the same change to 100 lines of code.

Now there are different kinds of code of course. It's much harder to change a monolithic function which uses and reuses the same variables all over the place than a group of functions with nicely separated responsibilities -- but that division must be produced by the desire to separate responsibilities, not by retarded precognition that you might want to reuse some of the functions.

Problem is that "good object oriented design" simply doesn't exist, unless produced by the process of gradual refactoring to accommodate actual requirements as they appear, then you can look back at it and notice that it's nice and modular and allows easy extensibility.

When, on the other hand, OOP fagdrizzles like you try to produce "good OO design" in advance, by adding abstractions, extension points, customizable functionality that you don't need to use yet, and so on, you can easily blow the size of the code 10x, and make it 100x harder to actually extend because of course none of your extension points quite fit the new requirements. And then you look at your 10000 lines of code and think -- well, the problem is that it's not customizable enough, I have not added an IOC AOP VisitorFactoryFactoryFactoryAdapter here, where I really want it now. While you could have done it as simple as possible with 1000 LOC and it would have been 100x easier to extend when and how you wanted it.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List