Автор Тема: between many classes Cheap Kobe 9  (Прочитано 306 раз)

canter12

  • Постоялец
  • ***
  • Сообщений: 160
    • Просмотр профиля
between many classes Cheap Kobe 9
« : 29 Ноябрь 2014, 14:54:57 »



between many classes

I think a simple answer is that this is where methods come in handy. If your "business rule" is that a mobile's stat is the sum of the native stat and all modifications that items would make, then my recommendation is to give stats to both mobile and items (more on that later) and then give your mobile class a method such as getStat($statName) which is responsible for doing the summing Cheap UGG Outlet Shoes Sale. This might be called the 'facade' design pattern (you present a clean interface to the outside world, obscuring the detail that items modify stats). To pull this off cleanly, mark your member properties as protected or private and only allow the other parts of the app to use the getter.

With respect to the question of giving multiple classes many of the same properties/behaviors, there are several options Cheap Kobe 9. The most basic (and probably wrong in this case) is to give them a common ancestor, such as 'statableEntity'. This is a poor choice because PHP is a inheritance language, and being statable is not inherent to your classesBasketball Shoes 2015,Kobe 9,KD 7,Lebron 12 Shoes,Air Jordan.

The second choice is PHP's relatively new feature called Traits. This is a fair bit better than class inheritance, because it starts to feel like multiple inheritance. This is a good option if the behavior is literally identical no matter which class needs the trait <Buy Kobe 9 Online.

The third choice is to use an interface. In this option, all classes implementing the interface need to have the same methods, but they do not all need to use the same code in the method body. This is a good choice when the classes adhering to the interface might want to implement the behaviors a little differently.

I think in your case, I recommend interfaces, because a person's stats may respond to context in different ways compared to the same stat on an item (for example, maybe the current value of an item's stat is reduced because the item is 'old' or 'needs repair', or the stat on a person changes with hunger, etc.).