The Artima Developer Community
Sponsored Link

Suggested way designing constructor calls.

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:

Suggested way designing constructor calls.

Posted by Jason Price on 01 May 1998, 5:15 PM

How about this


public class CoffeeCup {

public final static MIN_INNER_COFFEE = 0;

// defs of sizes...
private int innerCoffee;
private int size;


public CoffeeCup() {
this(SHORT);
}

public CoffeeCup(int size) {
this(size, MIN_INNER_COFFEE);
}

public CoffeeCup(int size, int startingAmount) {
size = SHORT;
innerCoffee = startingAmount;
}


This way, you only need to refer to the minimum innerCoffee value once instead of twice.



Replies:

Sponsored Links



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