Maintain item maintenance for a items in a class created by developer
using subclass per item
If anyone has an idea, I couldn't think of a better way to phase the
question.
I'll try to not make this to complicated an explination.
I'm writing a "quotes" class that is the main class. This class has
"overall" functions that preform calculations based on "items" stored in
its array. Suffice it to say, the end-developer will call it as $q = new
apiQuote/quote().
Then, before it's of any use, the first item must be added and it's
properties set so it can do it's "own" calculations. Something like
$q->createItem(). Once the item is created with this call, an "item" of
the class "item" is added to an array in "quotes" named "items".
The currently editable item, $q->item is always the last one added to the
array via the createItem method. Which looks like:
public function createNewItem() {
$this->items[] = new item();
$this->item = $this->items[count($this->items)-1];
}
I was looking to add an editItem method, whereby the parameter would be an
integer representing item index in the array and would set $q->item to the
latest item. Thus far, while I'll test it in a minute, as far as I can
think, this should work, however, I'd like a better way.
What I'm curious about, is if anyone has any suggestions on a better way
to go about this. I tried looking for a "cards/deck" php example, but all
I could find was array shuffles, which is kinda useless here. I know how
to do such associations in .NET and thought this would be just as easy,
but I don't have the same property abilities in PHP that I have in a .NET
language, thus negating what I'm used to in created this kind of
"class/subclass[items]" type structure.
Really I would just like to know if anyone has done anything similar and
if I'm doing things to the "best of ability" or if there might be a better
way, via PHP, to allow an "end-developer" to call on one main class and
create a list "items" based on a subclass that can later be used for
methods of the main class?
I really hope this sums it all up well and I havn't gone outside the
guidelines of "question asking" here, but I can't think of a better place,
other than maybe Code Review to pose such a question and get great
developer feed back. If y'all feel I need move it to Code Review, let me
know. My main reason for choosing this over CR is this site tends to get
faster responses.
No comments:
Post a Comment