c# - Call method from caller class and avoid circular dependency -
i have windows forms application contains of 3 projects in 1 solution.
hall.client <-- winforms
hall.admin <-- winforms
hall.processor <-- class library
hall.client , hall.admin need hall.processor reference. hall.processor can't add reference both hall.client , hall.admin because of circular dependency. need instance of each caller class in hall.processor
in hall.client have class called canopy
public class canopy : system.windows.form { public void setprocessname(string name) { this.txtprocessname.text = name; } } in hall.admin have class called roof
public class roof : system.windows.form { public void setprocessname(string name) { this.txtprocessname.text = name; } } i have method in hall.processor inside builder class
public class builder { form form; public builder(form form) { //here main problem. //if caller class hall.admin.roof this.form should hall.admin.roof //if caller class hall.client.canopy this.form should hall.client.canopy } public void setprocessname() { //how call method in caller class directly class //if(admin.roof) form.setprocessname("something admin"); //if(client.canopy) form.setprocessname("something client"); } } i need suggestion how solve problem. there design pattern related problem?
decouple classes each other through use of interfaces. can have interfaces declared inside processor library, or better yet in separate library, shared between client, admin , processor projects. checks form iroof or form icanopy.
note however, in case nothing prevent admin implementing icanopy or client doing iroof. if issue, make interfaces internal, , control visibility other assemblies via [assembly: internalsvisibleto("assembly")] (see "friend assemblies").
further, search web "dependency injection".
Comments
Post a Comment