Re: Rules for constructors
From: Chris Smith (cdsmith_at_twu.net)
Date: 03/17/04
- Next message: Matt Humphrey: "Re: Process.waitFor() vs. Process.destroy()"
- Previous message: Collin VanDyck: "Re: Problem: Nesting XML subtrees in a document with DOM"
- In reply to: Alex Hunsley: "Rules for constructors"
- Next in thread: Chris Uppal: "Re: Rules for constructors"
- Reply: Chris Uppal: "Re: Rules for constructors"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 17 Mar 2004 09:41:29 -0700
Alex Hunsley wrote:
> Anyway, what exactly is the moral of this tale?
>
> I suspect it's either
> a) always check your class is initialised,
> as per
> http://www.javaworld.com/javaworld/jw-12-1998/jw-12-securityrules.html,
> but this is a bit security-paranoid
>
> b) never call non-final methods from your constructor
> (or else they will be overridden causing chaos as I have experienced
> today)
> c) overridden methods should not access member variables that are
> from this class - should only access superclass member variables
I consider it to be somewhere between (b) and (c). Namely,
1. Strongly favor implementations that don't call non-final and non-
private methods from constructors of non-final classes.
2. When such method calls do exist, document this obviously, and don't
access any object state from these methods. (Even limiting state to
that of superclasses is not enough; I can construct a three-level class
hierarchy in which that's not safe either.)
-- www.designacourse.com The Easiest Way to Train Anyone... Anywhere. Chris Smith - Lead Software Developer/Technical Trainer MindIQ Corporation
- Next message: Matt Humphrey: "Re: Process.waitFor() vs. Process.destroy()"
- Previous message: Collin VanDyck: "Re: Problem: Nesting XML subtrees in a document with DOM"
- In reply to: Alex Hunsley: "Rules for constructors"
- Next in thread: Chris Uppal: "Re: Rules for constructors"
- Reply: Chris Uppal: "Re: Rules for constructors"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|