• Skip to main content
  • Skip to footer

Agile Pain Relief Consulting

Scrum and Agile Training and Resources

  • Certified Scrum Training
    • Certified ScrumMaster (CSM) Training
    • Advanced Scrum Master Certification (A-CSM)
    • Certified Scrum Product Owner (CSPO) Training
    • Private Scrum & Agile Training
      • Agile Foundations Private Training
    • Choose the Right Scrum Training for Your Needs
    • FAQs and Policies
  • What Is Scrum
  • Resources
    • A Jargon-Free Introduction to Scrum
    • *NEW* Agile Glossary and Reference Library
    • The Guide to Effective Agile Retrospectives
    • Online Agile Teams Game (Beta)
    • Five Steps for Creating High-Performance Teams FREE ebook
    • Foundational Scrum Free Learning Series
    • The Story of a Sprint
    • Free Virtual Scrum Meet-Up
    • Get Scrum Education Units (SEU)
    • Articles & Interviews
    • Newsletter
  • Blog
    • Scrum by Example – Stories for the Working ScrumMaster
    • Beyond Scrum Blog Series
    • Scrum Anti-Patterns – How We Hold Back Our Scrum Teams

Don’t call overridable methods in constructors

October 4, 2007 by Mark Levison Leave a Comment

MS has a rule about this in FxCop. PMD has a rule:

ConstructorCallsOverridableMethod. In both cases the point is to discourage the following weird behaviour. From Eclipse:
public abstract class CellEditor {
    protected CellEditor(Composite parent, int style) {
        this.style = style;
	System.out.println("CellEditor constructor");
        create(parent);
    }

public void create(Composite parent) {         Assert.isTrue(control == null);         control = createControl(parent);    }     protected abstract Control createControl(Composite parent) }


…..

public class HyperlinkCellEditor extends TextCellEditor {
	public HyperlinkCellEditor(Composite parent, int style, otherParams) {
		super(parent, style);
		System.out.println("HyperlinkCellEditor constructor")
	}

protected Control createControl(Composite parent) {             System.out.println(“createControl“);     return newly created control;       } }


When run the output of this code is:

CellEditor constructor
createControl
HyperlinkCellEditor constructor

Sadly this means createControl (which you must implement) doesn’t have access to local variables (they’re not yet initialized) nor does it have access to HyperlinkCellEditor’s other params. Now we have to initialize our control in two parts. The generic part is done in the createControl and the part specific to our data in the constructor. Its bad enough that they called an overridable method from the constructor. Far worse that they made it abstract. I wasted a chunk of time trying to debug this mess a few days.

To the eclipse guys: come on not even MS would allow this to be checked into the .NET framework. Who thought this was a good idea?

Sorry for the lack of posts in the last week a perfect storm of events has conspired to keep me busy.

Next up a post on the perils of protected variables – which stunningly Eclipse also uses.

Mark Levison

Mark Levison has been helping Scrum teams and organizations with Agile, Scrum and Kanban style approaches since 2001. From certified scrum master training to custom Agile courses, he has helped well over 8,000 individuals, earning him respect and top rated reviews as one of the pioneers within the industry, as well as a raft of certifications from the ScrumAlliance. Mark has been a speaker at various Agile Conferences for more than 20 years, and is a published Scrum author with eBooks as well as articles on InfoQ.com, ScrumAlliance.org an AgileAlliance.org.

Filed Under: Software Development Tagged With: Eclipse

About Mark Levison

Mark Levison has been helping Scrum teams and organizations with Agile, Scrum and Kanban style approaches since 2001. From certified scrum master training to custom Agile courses, he has helped well over 8,000 individuals, earning him respect and top rated reviews as one of the pioneers within the industry, as well as a raft of certifications from the ScrumAlliance. Mark has been a speaker at various Agile Conferences for more than 20 years, and is a published Scrum author with eBooks as well as articles on InfoQ.com, ScrumAlliance.org an AgileAlliance.org.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Footer

  • Certified Scrum Training
  • Private Training
  • Effective Agile Retrospectives
  • Agile Reference Library
  • About Us
  • FAQs and Policies
  • Site Map
  • Partners

Contact Us

  • 877-248-8277

Follow Us

  • LinkedIn
  • Mastodon
  • RSS


Subscribe for Scrum & Agile news and more resources





© 2011–2023 Mark Levison & Agile Pain Relief