The Artima Developer Community
Sponsored Link

Set / Get

Advertisement

Advertisement

This page contains an archived post to the Design Forum (formerly called the Flexible Java Forum) made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Set / Get

Posted by Andre Richards on 05 Apr 1999, 12:46 AM


>The set/get naming convention for state accessors is as good a
>convention as any. Hiding state change and access with accessor
>methods is an excellent idea. (If I had it my way, I'd do away
>with public fields entirely, but that would mean changing Java
>semantics.)

Sometimes I use an object purely as a data container, e.g.

/**
* This class represents a Trade transaction.
*/
public class Trade
{
public String Time;
public int TradeNo;
public String StockSymbol;
public String StockShortName;
public String Type;
public int Price;
public int Volume;

public Trade(String Time, int TradeNo, String StockSymbol, String StockShortName, String TradeType, int Price, int Volume)
{
this.Time = Time;
this.TradeNo = TradeNo;
this.StockSymbol = StockSymbol;
this.StockShortName = StockShortName;
this.Type = TradeType;
this.Price = Price;
this.Volume = Volume;
}
}

The object does not have a state as such, and using public fields removes a lot of tedious prorgamming work - writing get and set methods for every field would drive me insane.




Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us