tag:blogger.com,1999:blog-36547168.post2414688601320496580..comments2023-11-25T11:00:42.257+01:00Comments on Invisible to the eye: Defaulting to privateGiorgiohttp://www.blogger.com/profile/03558287012747987157noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-36547168.post-3410877550402975352009-11-16T23:01:27.881+01:002009-11-16T23:01:27.881+01:00Thanks Roman,
backward compatibility is important ...Thanks Roman,<br />backward compatibility is important for classes that are meant to be used externally and I'm sure you have a lot of them in Doctrine 2. :)<br />I just can't make class final anyway, unless I have already an interface which I can mock instead of the concrete class, which is a fine approach but not always practical. Otherwise, making everything final (such as method parameters and class members) would be very defensive.Giorgiohttps://www.blogger.com/profile/12689416577856305650noreply@blogger.comtag:blogger.com,1999:blog-36547168.post-84213118340690940062009-11-16T20:33:49.450+01:002009-11-16T20:33:49.450+01:00I think this is good advice and I second it. It es...I think this is good advice and I second it. It especially pays off the larger the system and the code base is and the larger the userbase of the codebase. Good API design is incredibly hard and backwards compatibility is a major issue. As soon as you have a protected member and your class is not final you can theoretically not even rename the member without potentially breaking BC. If the class was not intended to be inherited then it might be a good idea to make it final (this may have some negative consequences on testing/mocking though).<br /><br />It really pays off to invest in good APIs and member visibility is a very important part of that. Its easy to relax visibility later but much harder to go the other way around so starting with the lowest visibility that is needed to get the job done is good advice.<br /><br />Some random thoughts:<br /><br />- protected in Java actually allows access from all classes in the same package. Thats quite confusing to many people.<br /><br />- I only know of Scala supporting object-private accessibility but maybe others do, too. In Scala its: <br /><br />private[this] val foo = "hello"<br /><br />Good post!Unknownhttps://www.blogger.com/profile/00439059243350222311noreply@blogger.com