-
In order to call
MyClass::empty().empty
Do I need to implement an empty method in side MyClass? What would I write inside it? -
Following, I am not sure how such a call could work:
x = MyClass::empty().add("a").add("b")
Would this be simply calling the add method if it is empty?
In order to call MyClass::empty().empty Do I need to implement an empty method in
Share
What would you write inside it? What do you want it to do?
You’d have a class method named
emptythat returns something having anemptymethod that either (a) took no parameters, or (b) had them defaulted.It also needs to return something that has an
addmethod, and returns itself.It’d be easier/quicker if you described what you’re trying to do. It’s not immediately obvious.
Now you have no immediate way to get to the “inner” class’s list, unless you saved it in either
MyClass(sketchy, since the methods are class, not instance, method), or you save the return value from the last bunch of chained methods.But if you save the instance, what’s the point of doing it through
MyClass? Again, I can’t help but think you need to define what you’re actually trying to accomplish, rather than focusing on how you might accomplish it. What’s the goal?Firstly, there is no “add” method for an array. What you’re describing, as yet, makes no sense, unless you mean something like this:
Then:
But again: you’re mixing class and instance methods in a way I don’t find sensical. How do you want to access the array? What’s the point of
MyClass? Why not just use an array?Without any guidelines for what
MyClass‘s purpose is, telling you a reasonable way to implement it is difficult, because without context, what you’ve shown doesn’t make a lot of sense.