is there any way to get around `'public' function ...
# getting-started
h
is there any way to get around
'public' function exposes 'private' return type
?
d
Make the function private? 😄 🧌
In all seriousness, no, that's what you have to do. A public caller couldn't do anything with the return type anyways. So you might as well return either a public supertype or just
Any
h
shame
d
Not sure what you would want this to do even. What's your use case?
h
Perhaps this is just a dumb way to organize everything
the vector interface is ~1000 lines of code. i'd rather it be called
Vector
because that's the type which can do all the work, and keeps things generalized.
d
Well, you can just specify the return type to be
Vector
in this case, no?
h
That wouldn't potentially eliminate the stored array in the basic vector?
please forgive me for not understanding some of these type interactions. i think it's a very complex aspect of oop
d
No, you are still returning an instance of
BasicVector
. You are just not baking that into the method contract.
h
okay, great, thanks for the help
d
The method says "I am returning any kind of `Vector`", and that happens to be a
BasicVector
in this case
h
Okay, wonderful
another question, do you prefer to move out a bunch of "boiler plate" code for your class into another file as extensions or do you find that a sloppy and improper way to organize things?
d
Definitely, that's what extension are for. They act as "utility functions" that help with usage of the class. I usually only put "core functionality" into the class, anything else that can be seen as a combination of this core functionality, I would do as an extension.
h
in this case, i ported over most of the kotlin stdlib collection functions to
Vector
, but i didn't want to simply extend
List
or something because Vectors aren't lists, and I didn't want to extend
Iterable
because that brings along functions i don't want for vectors
alright, thank you kindly for your input