Yes, that is basically what I am doing.
But what my case is, to be more specific is that I am making as an exercise this card game which has more than one deck. (not normal decks, but decks full of special cards)
Now each deck has several methods, which i have put to Prototype_deck class.
Methods like:
Code: Select all
prototype_deck:New()
prototype_deck:Shuffle()
prototype_deck:DealACard()
prototype_deck:FindACard()
These are inherited to new card decks with:
Code: Select all
SpecialCardsDeck = Prototype_deck:New()
However, each player has his own playdeck that each contain the same 15 cards in them. But there is one special case with these player decks, for at beginning of them they need to pick one certain card (called "aboa") and put it to the bottom of the deck.
I can of course do it by adding new method to prototype deck:
Code: Select all
function prototype_deck:PutAboaToBottom()
stuff
endfunction
But since I am aiming for my code to be reusable, which means that if i make another game which has card decks, I am hoping that I can simply copy paste the whole "prototype_deck" class and simply use it at new game. And in this case, the PutAboaToBottom() method is such a specific class that it is unlikely there is similar method needed in any other games decks, and for that reason I would like it to be separate from the "prototype_deck" and instead be specific to these "player_deck[n]"s only.
I could make it on fly as:
Code: Select all
player_deck[n]:PutAboaToBottom = Function () stuff EndFunction
But then that piece of code gets in middle of code making it hard to find afterwards, and it also wont be listed in list of functions.
So for both better accessibility as well as style reasons, I would wish to make that method first at place where i could put all the specific to this game methods, and then copy that function to each of those player_deck[n]:
Code: Select all
function PutAboaToBottom()
do the stuff
endfunction
for n=1 to 4
player_deck[n]:PutAboaToBottom = PutAboaToBottom
next
This would be from maintainability and understandability point of view the best solution i can come up with, but I dont know how to actually do it.