Hacker News new | ask | show | jobs
by akavi 641 days ago
Can you make the Record class private to a module, and only export a static function that constructs them?

(I know very little about Java)

1 comments

To a degree, yes, that’s possible. But leaking a private type over module boundaries is bad form, so a better (though possibly over engineered solution) would be to have a separate public interface, implemented by the private record type, and the static function would have that interface as return type.
Why is it bad form to expose a record type only via custom functions and not its field accessors? Isn't this just like exposing a more usual object with its public functions and private functions remain inaccessible?