Link to home
Start Free TrialLog in
Avatar of navaru
navaruFlag for Romania

asked on

Items Class in PHP, abstract class products, example

Hello,
I am building an inventory, where items will be some sort of products.

I have a dilemma in how to write this class in php5, I want to write an abstract class item.

Now, which is a better approach, to write a separate DataManager interface to create and manage items (ex. add/update them into the DB) or to create methods inside the items class?

If you have an example of how to approach this situation feel free to share.

Thanks,
Eugen
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Is this a classroom assignment?  Can you show us an example of the code you've tried already?
Avatar of navaru

ASKER

It's not a classroom assignment, I'm new to OOP and I see that almost everyone has his own method of creating abstract classes. I quite don't fully understand some aspects, how should I approach this to be maintainable over time if I want to extend the items properties and category.  
This should answer your questions:

"PHP 5 introduces abstract classes and methods."
http://php.net/manual/en/language.oop5.abstract.php

 As this describes, an abstract class cannot be instantiated, but instead it is subclassed with concrete classes that can be.  I can answer any OO questions, but I am not a PHP expert so can't help with the details.  Glad to help further if I can...Mark
Just going back to this in the original post, "I want to write an abstract class item."

Please tell us: why do you want to do that?  Can you show us an example of the code you've tried already?

Thank you, ~Ray
Avatar of navaru

ASKER

In the application I want to build, an item has properties and belongs to a category. Some of the Items are products to be sold, some are office inventory (furniture, appliances and so on).

I wanted to know how to best approach this so I can modify it over time and to have an easy readability over the code.

I thought it this way, every object is an item, but with different properties and purposes, but every item has a basic set of properties that I need in all of the situations.

abstract class item
{
  // basic data model
  // basic methods
}

interface dataManager
{
  // CRUD
}

products extends items implements dataManager
{
  // extra details
}

That seems like a reasonable design.  Can you please post the code you have started with?
ASKER CERTIFIED SOLUTION
Avatar of marklorenz
marklorenz
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
btw, you may want to put this question in the OMG UML zone.
Avatar of navaru

ASKER

I was a good Idea, thanks