X-Received: by 2002:ac8:267d:: with SMTP id v58mr75487290qtv.340.1555535147441; Wed, 17 Apr 2019 14:05:47 -0700 (PDT) X-Received: by 2002:a81:9ad0:: with SMTP id r199mr71668490ywg.310.1555535147230; Wed, 17 Apr 2019 14:05:47 -0700 (PDT) Path: csiph.com!3.eu.feeder.erje.net!feeder.erje.net!fdn.fr!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!t9no2684974qtn.0!news-out.google.com!i54ni1215qte.0!nntp.google.com!t9no2684966qtn.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.java.programmer Date: Wed, 17 Apr 2019 14:05:46 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=50.78.95.177; posting-account=2czF5goAAAD4GBMPIGV4KcD2K4PhoB_H NNTP-Posting-Host: 50.78.95.177 References: <109a7224-f392-46c3-bf56-7d8bf2bfb4bf@googlegroups.com> <13t97bxk9km7n$.ooqi8n8ocm7f$.dlg@40tude.net> <13ak6boysjgrh$.1h4x7tkjgs00q$.dlg@40tude.net> <7ivllvz2ukra$.qlcrlm81adao.dlg@40tude.net> <28f31a7a-5bdf-4eaa-ad70-df6c0751b5ff@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <8d955e2b-8532-4591-9868-c86aa1913d01@googlegroups.com> Subject: Re: Java variable access From: Eric Douglas Injection-Date: Wed, 17 Apr 2019 21:05:47 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Xref: csiph.com comp.lang.java.programmer:38927 On Wednesday, April 17, 2019 at 3:36:33 PM UTC-4, Daniele Futtorovic wrote: > > If you leave off the validation and just declare class variable public = double unitPrice, you either validate it where it gets used or never valida= te assuming it's ok to just throw an error where it would be used if it som= ehow gets an invalid value. >=20 > That has to be the worst advice I've read in quite a while. >=20 > --=20 > DF. I would agree that's probably not a good idea, but I'm sure I've seen it do= ne.. Personally I think option 2 sounds better.. preferably use an IDE or plugin= that can create getters and setters for you and do the validating for you = if there are multiple fields with the same validation requirement. If not = then just build in a framework for it, try to prevent duplicating code as m= uch as possible.