Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!mx05.eternal-september.org!.POSTED.50-76-45-78-ip-static.hfc.comcastbusiness.net!not-for-mail From: markspace Newsgroups: comp.lang.java.programmer Subject: Re: multiple inheritance in Java Date: Mon, 01 Jul 2013 18:59:38 -0700 Organization: A noiseless patient Spider Lines: 33 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Tue, 2 Jul 2013 01:54:10 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="50-76-45-78-ip-static.hfc.comcastbusiness.net:50.76.45.78"; logging-data="25542"; mail-complaints-to="abuse@eternal-september.org"; posting-account="markspace" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130620 Thunderbird/17.0.7 In-Reply-To: Xref: csiph.com comp.lang.java.programmer:24569 On 7/1/2013 5:47 PM, Stefan Ram wrote: > Supersedes: > . Would it be so bad to implement this using public fields > instead of classical delegation? Public fields: > > . I only ask, because public fields usually are frowned upon > in OOP, but what would be the drawback here, especially when > those fields are final? > With private fields, you can enforce some constraint on color and position. Without it, you'll constantly have to check in every method if those constrains are still valid or not. There's other reasons. Public final fields aren't thread safe, for example, so you're encouraging bad style, imo. You also allow any arbitrary changes to your class this way, and forgo encapsulation. This also seems bad style. You can forgo inheritance if you like, ColorPosition does not have to be a type of Position (or Color), but encapsulation seems too basic and desirable to give up. You might be able to make the case for some simple examples, but I think problems with this idea would become apparent quickly in even a modest sized project. What's your goal here?