Search Unity

[TUTORIAL] Solving common GUI problems with Open Closed Principle

Discussion in 'Community Learning & Teaching' started by uraniumbathtub5, Aug 31, 2013.

  1. uraniumbathtub5

    uraniumbathtub5

    Joined:
    Apr 7, 2012
    Posts:
    59
    Last edited: Sep 1, 2013
  2. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    This violates much more fundamental principles like Single Responsibility and Separation of Concerns.

    If you wanted to replace your inventory with NGUI (as an example) you would have to rewrite your Item classes potentially impacting your item system which has nothing to do with the view.

    Why should an item know anything about an inventory? Does that mean if you allow you items to be auctioned your item class now has to know about auctions? If you wanted to change how your inventory worked, for example to require a slot to place the item in when adding, you have to go through and adjust your item code.

    Does this mean this kind of system is never worth while, no, of course not, but to pose it as the right way to audience of beginners...
     
    Last edited: Aug 31, 2013
  3. uraniumbathtub5

    uraniumbathtub5

    Joined:
    Apr 7, 2012
    Posts:
    59
    Doing this helped me overcome many problems with a game I was creating and it had all the features I needed. It is probably necessary to have features like removing the item and adding the item be done by an event/listener system though in SOME cases, when you have more complex items.

    I think this is perfectly good for displaying the item though. I appreciate the feedback makes me think about the way I program my systems.