Friday 15 July 2011

c# - Structural or Messenger in .net 4.5 -



c# - Structural or Messenger in .net 4.5 -

i want inquire best practice in case :

suppose have kind of code

class baseclass { protected bool checkresponse(string response) { if (response == somecondition) { runerrormessages(); homecoming true; } homecoming false; } } class derivedclassa { connectorclass myconnector = new connectorclass(); private void mycommand(string req) { string resp = await myconnector.senddatatoserver(req); if (!checkresponse(resp)) dosomething1(); } } class connectorclass { public async task<string> senddatatoserver(string req) { string resp = await server.waitforresponse(req); homecoming resp; } }

it improve or 1 below?

abstract class baseclass { public baseclass() { messenger.default.register<string>(checkresponse); } public abstract callwhateverderivewant(); private void checkresponse(string response) { if (response == somecondition) { runerrormessages(); } else callwhateverderivewant(); } } class derivedclassa { connectorclass myconnector = new connectorclass(); private void mycommand(string req) { await myconnector.senddatatoserver(req); } public abstract callwhateverderivewant() { callsomething(); } } class connectorclass { public async task senddatatoserver(string req) { string resp = await server.waitforresponse(req); messenger.default.send(resp); } }

for information, there lot of derive class derived baseclass, , it's behaviour similar derivedclassa.

please help me find out best way solve case.

thanks before.

in situation, reply question depends on intent of program. these 2 cases not @ logically equivalent.

in first example, checking response condition. presumably complicated procedure belongs in own method. way code written, checkresponse takes place in base of operations class, while derived classes contain conditional logic statements process boolean result. use-case when checkresponse method same across classes, result differs.

in sec example, checkresponse method , conditional logic uses exist in base of operations class, uses of both same across instances; calling method on derived classes 1 time conditional logic has been executed. derived class has no thought result of checkresponse was.

so, objective trying achieve?

c# .net-4.5 mvvm-light

No comments:

Post a Comment