JLinX – Blog

Weblog von Jan Linxweiler

How to design a single method

Filed under: Development,Software Engineering — Jannis at 10:02 pm on Sunday, April 22, 2007

  • The name of the method should describe what the method actually does.
  • A method should do one and only one thing.
  • A method should either DO something or RETURN something.  If it returns something, you should be able to call the method over and over with no negative consequences.
  • The method should be viewable without scrolling.  Fewer than 10 lines of code is desirable (my pain point).
  • The method should take few arguments.  If the method needs more, refactor to require and object that contains all the information required (parameter object).
  • The method depends only on method parameters or members passed into the class constructor.
  • A method should only have one indented code block – don’t nest code blocks.  Extract method first.
  • Don’t try/catch in a method unless you can handle the exception or add value.  Let the exception bubble up to a point where you can actually do something about the exception.

(Quelle: How to design a single methodJeffrey Palermo)

No Comments

No comments yet.

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.