⸻ Ban DHMO 🇦🇺 ⸻@aussie.zone to Programmer Humor@lemmy.mlEnglish · 18 days agoThe C++ learning processaussie.zoneimagemessage-square129fedilinkarrow-up1875arrow-down17file-text
arrow-up1868arrow-down1imageThe C++ learning processaussie.zone⸻ Ban DHMO 🇦🇺 ⸻@aussie.zone to Programmer Humor@lemmy.mlEnglish · 18 days agomessage-square129fedilinkfile-text
minus-squaremagic_lobster_party@fedia.iolinkfedilinkarrow-up2arrow-down2·18 days agoIn your example, the declaration of ArrayList look like: public class ArrayList extends AbstractList implements List { } The dependence on AbstractList is public. Any public method in AbstractList is also accessible from the outside. Compare it with my solution: public class ArrayList implements List { private AbstractList = new AbstractList(); } Nothing about the internals of ArrayList is exposed. You’re free to change the internals however you want. There’s no chance any outside code will depend on this implementation detail.
minus-squareSpaceNoodle@lemmy.worldlinkfedilinkarrow-up1·17 days agoThat’s not C++, which has more control over such scope.
In your example, the declaration of ArrayList look like:
public class ArrayList extends AbstractList implements List { }
The dependence on AbstractList is public. Any public method in AbstractList is also accessible from the outside.
Compare it with my solution:
public class ArrayList implements List { private AbstractList = new AbstractList(); }
Nothing about the internals of ArrayList is exposed. You’re free to change the internals however you want. There’s no chance any outside code will depend on this implementation detail.
That’s not C++, which has more control over such scope.