views:

121

answers:

3

What do you call the design where the object's constructor is responsible for all/any subsequent actions. Usage of this class involves simply creating an instance and then it's all fire-and-forget.

A silly example:

public class Order
{
   public Order(int ammount,Product type)
   {
       Ammount = ammount;
       Namespace.OrderManager.RegisterNewOrder(this);
       Namespace.WarehouseManager.Substract(this);          
       Namespace.OrderManager.Invoice(this);
       Namespace.DeliveryManager.Deliver(this);
       .. well, you get the point;

   }

   // Called back later from DeliveryManager
   public void OrderHasBeenDelivered()
   { 
       //save some data to the DB, or notify the UI
   }

   // Called back later from OrderManager
   public void OrderHasBeenCanceled()
   {
       Namespace.DeliveryManager.CancelDelivery(this);
   } 
}

... usage of the Order class :

   public void CreateOrder_click(object sender, EventArgs e)
  {
            new Order(50, CDs);
            new Order(10, DVDs);
            new Order(10, DVDs);

  } 

Edit:

Well, the difference between using this and a simple static method, is that the newly created Order object is going to be used in many different places, just not by the function/thread/object that created it.

I simply create the order object, it registers itself with the OrderManager, then the OrderManager will close the order at a later time. I don't throw the object away per-se, it will continue to exist in the app.

+2  A: 

This looks more suited for a (static) method than creating an instance of a class which you then throw away!

I am not sure if this has a name, I am hoping it doesn't! Maybe this is a well known anti-pattern...

...check this out: http://geoffrey.vandiest.biz/post/Anti-Pattern-3-Overloaded-Constructor.aspx

Moron
+3  A: 
  • "A Bad Idea"?
  • "Untestable"?
  • "Procedural mess"?
  • "The Anti-Object-Oriented Anti-Pattern"?
Theo
lol :-)) and then a second lol, cause comments must be 15 chars min
Radu094
A: 

This is no pattern.

this. __curious_geek