Path: csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Robert Klemme Newsgroups: comp.lang.java.programmer Subject: Re: can someone chk is this code ok and if i can make it better please state how Date: Sat, 7 Jan 2017 14:23:13 +0100 Lines: 62 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net uhAR2mjw9G00FYQoW57OIwJUlUvAiH/jk1KojkYzhnSiI2rIA= Cancel-Lock: sha1:AXKq/GUYjXOFoJGSv7OUPSKsCP8= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 In-Reply-To: Xref: csiph.com comp.lang.java.programmer:36170 On 06.01.2017 21:38, SuperGiirl wrote: > public class Gadget > { > private int Weight; > private double Price; > private String Model; > private String Size; > > > public Gadget(int theWeight, double thePrice, String theModel, String theSize) > { > Weight = theWeight; > Price = thePrice; > Model = theModel; > Size = theSize; > } > > > public int getTheWeight() > { > > return Weight; > } > public double getThePrice() > { > return Price; > } > public String getTheModel() > { > return Model; > } > public String getTheSize() > { > return Size; > } Yet another addition to the other remarks: some of the types look suspicious and might be better changed, depending on the intended usage of the class. int for weight might be OK, but if it is in kilograms and needs to express grams (i.e. fractional values) a double might be more appropriate. Definitively state the unit in the JavaDoc. You can get easily into trouble when representing prices as double. Apart from the missing currency (again: state in JavaDoc if it is fixed) the impedance mismatch between binary representation of double and decimal usage of prices might cause trouble when doing calculations. Using String for a size seems quite wrong. Either size is represented by some abstraction (e.g. S, M, L, XL, XXL) or by some measurement (16cm) so for the former you would use an enum and for the latter a numeric type or a type combining a measurement and a unit. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/