Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Having classes modify higher order classes?

Asked by 8 years ago

Yeah, this may seem a bit weird and complex as I'm going far into the concepts of OOP, but here me out. I have 3 objects: a GameBoard Object, a Card Object, and an Effect Object.

GameBoard has-a Card, and Card has-a Effect.

If I wanted Effect to provide instructions for GameBoard to modify its descendants, how would I do so? I was wondering if I could simply have a high order class like GameBoard read a function in from Effect, but I'd assume the variables of that function and all of its effects wouldn't be understood as they don't exist within Effect. Maybe even loadstring()()? I've been pondering this for months now and I wonder how I should revise my thinking.

1
Counldn't you invoke the card to invoke the effect? ie: Have the gameboard call a function of Card that calls a function of effect and returns data back to GameBoard BlackJPI 2658 — 8y
0
Yes but what data am I to return? Functions of gameboard that are not visible to effect? randomsmileyface 375 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

My best shot at this is to pass a reference to the GameBoard itself to Effect.

Let's say you have a method of Effect - fire(), which reads the desired function. Make fire() take the parameter of GameBoard, so that Effect can use a reference to GameBoard

It would look like

Card.Effect:read(self)

Ad

Answer this question