I've decided to learn OOP and what a better way then to write your own CMS. So anyways after some tutorials and playing around with OOP along with xdebug (most awesome debugging tool, honestly I only use it because the errors are colorful and aren't boring) I've come up with some code. This code checks the environment the php script is running in. Can you guys critique my OOP coding style? Thanks.
Your better off starting with something simple... such as using proper objects... not init
Example... a shopping cart...
A shopping cart contains items... which in turn must have a price, title and description... so... to enforce that using OOP you need the following:
An abstract class for the item... which contains the methods: get_price, get_description, get_title... then any item such as a book would extend the abstract item class... this then enforces that those methods exist.
Then you need a shopping cart class... this class needs a method like this: add_item(item $item);
Notice the type hint... this means that when an object is passed to the shopping cart, it will ONLY ACCEPT items that extend the abstract item class. This ensures it gets the correct items and it knows that those 3 methods exist: get_price, get_description, get_title.
Since the shopping cart uses the items... it should be done using aggregation because once you delete the shopping cart... then items should still exist
I would write the code.... but really dont have the time.
You do not have permission to post replies to topics in this board. If you want to join in with discussions and create new topics please register. If you want to register your own free account with us, please click here.