jeudi 9 avril 2020

Facade pattern and array of objects -- code looks non-standard?

Beginner programmer here, with limited coding standard knowledge. I have code that (what I think based on what I've been reading) follows a Facade pattern, and I'm trying to make it work for an array.

Not that there is a problem with it -- the code runs correctly and does what I intend to do. My only concern is that I think the code looks weird, but I can't explain why? I'd like someone to please point out why this is OK or wrong, and what I may be able to do improve it?

Please do note that the Order class has many more functions in it that are called in the same way, so a general code cleanup activity may be needed -- I just don't know how to start. I was initially thinking of moving out the affected calls (like CancelOrder) in to the current class so I wouldn't need to do weird code acrobatics, I think that would also invalidate the pattern?

    public void DoSomething(Order[] orders)
    {
        //Original code had only the following to call CancelOrder(), which cancels ALL orders
        //order.CancelOrder();

        //However, since I am now receiving an array, I think my revision looks weird?
        orders[0].CancelOrder();

        foreach(Order order in orders)
        {
            ...
        }
    }

Aucun commentaire:

Enregistrer un commentaire