Code from your fellow developers

It's almost a law: whenever you take over code from another developer, you start to moan and complain about the state of that code. It's awful, terrible, the worst piece of code you've ever seen. I am no exception. However, when I took over some code from a colleague who left the company I found this gem. I think I am right in complaining about this piece of code. (FYI this is almost an exact copy of what I found in the codebase, except for it being an console application and the classnames…)

namespace ConsoleApplication9

{

    class Program

    {

        static void Main(string[] args)

        {

            Customer customer = new Customer();

            customer.Id = 42;

 

            Order order = new Order();

            order.Id = 64;

 

            customer.Save(order);

        }

    }

 

    public class SaveableEntity

    {

        public int Id { getset; }

 

        public void Save(SaveableEntity entity)

        {

            entity.Id = Id;

            SaveService.Save(entity);

            this.Id = entity.Id;

        }

    }

    public class Customer : SaveableEntity

    {

        //...

    }

 

    public class Order : SaveableEntity

    {

        //...

    }

}

 

Now, please tell me what you think of this…