i am using Java and i have this hierarchy
class Seq
class For extends Seq
interface SeqIt
Class ForIt implements SeqIt
And ForIt has a constructor: public ForIt( For x ) //takes For objects
Till now everything works fine.
Now I want to make a new class called FU that gets access to any ForIt objects I created.
And this FU class must have a method with this signature public static int sum1(For MyFor)
For example if ForIt objects have inside it an array called myArr. This method sum1 is supposed to return the sum of all elements of the array myArr inside MyFor object
How can I create this class FU?
The 2 ways I can think of are:
ForItclass, add it to yourFUclass – when you are done, call the sum methodForItclass constructor call a static method of theFUclass to let it know a newForItwas createdI would personally use option 1 as it avoids static variables which can be a pain to work with. Option 2 would work for a simple use case.
Option 1 is fairly straigthforward (create a
FUobject, and every time you create aForItinstance, add it to theFUobject).Option 2: