Refactoring Derived Classes' Methods to Common Base Class' Method? (C#) -


In my project, I have some functions in the devised classes that are similar to one section, which is different in each.

I want to draw the law up to the base class.

Functions look like this:

  func (parameters) {// normal bits if (someVar == "value1") {htmlFilename = line; } And if (someVar == "value2") {subVideoLink = line; } And if (someVar == "value3") {linksH2HeadingWritten = true; } // common bits}  

where the center lines of different functions look like everyone but different values ​​for "somevar" and different variables in "variable = line"; Format.

This is a normalized form:

  if (someVar == "CommandName") {variable = line; }  

The function can be found in the dictionary < String commandname, riff string & gt; to send, but it seems that I can not make a dictionary with the referee string ...

Then I call the boolean cases of 'variable' to be "true" or "false" We will remove the values ​​with string versions along with the values.

Is there a better way to do this?

A better method is a virtual (or summary ) The method in the base class that you call in func , then in each of your sub-classes you can override the method with specific instructions and func subclass Will use the behavior of

  Public class MyBase {Protected Virtual Zero DoCommand () {emit new notified exception (); } Public Zero Func () {... DoCommand (); ...}} Public class MySubClass: MyBase {secure override zero doCommand () {...}}  

Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -