c# - Best practice for passing parameters, which can take two values -



c# - Best practice for passing parameters, which can take two values -

how write better?

public void foo(bool isstart) { // code [common] if (is start) { // code [start] } else { // code [end] } // code [common] }

or

public enum myenum { start, end } public void foo(myenum param) { // code [common] switch (param) { case myenum.start: // code [start] break; case myenum.end: // code [end] break; } // code [common] }

update: i'm looking little solution. "common", "start" , "end" parts short, not want split foo several methods.

how about:

public class foo { public void start() { precommon(); // code [start] postcommon(); } public void stop() { precommon(); // code [stop] postcommon(); } private void precommon() { // code [pre-common] } private void postcommon() { // code [post-common] } ... }

methods have single responsibility easier read, easier understand , easier maintain.

c# .net coding-style

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -