c# - Solution for circular dependency -



c# - Solution for circular dependency -

i have below 2 classes in 2 projects , each class needs phone call other class method. cannot add together reference each other because creating circular dependency.

i know must utilize interface resolve issue not able comeup answer. please allow me know how implement & resolve this.

project test2

namespace test2 { public class classtest2 { public string getclasstest2() { homecoming "classtest2"; } } }

project test1

namespace test1 { public class classtest1 { public string getclasstest1() { homecoming "classtest1"; } } }

you'd need 3rd project in define interface:

public interface iclassnameaware { string getclassname(); }

from both existing projects, reference new assembly , create classes implement interface:

public class classtest1 : iclassnameaware { public string getclassname() { homecoming "classtest1"; }

now both classes still can't access eachother directly, take iclassnameaware variables, ie:

public bool classnamesequal(iclassnameaware otherclass) { homecoming getclassname().equals(otherclass.getclassname()); } }

c# .net visual-studio-2012 interface circular-dependency

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -