The disconnect point is the need to access private variables of any of these classes or properties that are specific to them.
If you want to encapsulate and share behavior, you use the Command Pattern. It looks something like this:
public interface ICommand {
void ExecuteOnPreRender(WebControl control, EventArgs args);
}
public class SharedPreRenderCommand : ICommand {
public void ExecuteOnPreRender(WebControl control, EventArgs args) {
}
}
public class RoleImageButton : ImageButton {
private ICommand onPreRenderCommand = null;
public void SetPreRenderCommand (ICommand command) {
onPreRenderCommand = command;
}
protected override void OnPreRender(EventArgs args) {
if (null != onPreRenderCommand) {
onPreRenderCommand.ExecuteOnPreRender(this, args);
}
else {
base.OnPreRender(args);
}
}
}
public class RoleButton : Button {
private ICommand onPreRenderCommand = null;
public void SetPreRenderCommand (ICommand command) {
onPreRenderCommand = command;
}
protected override void OnPreRender(EventArgs args) {
if (null != onPreRenderCommand) {
onPreRenderCommand.ExecuteOnPreRender(this, args);
}
else {
base.OnPreRender(args);
}
}
}
... , , , RoleButton .., . RoleButton/RoleImageButton- ; , - :)
/ , , , RoleButton RoleImageButton ... . , , , , .
, , - , , # .
... , , , :
public class Roles {
public bool PrimaryRole;
public bool SecondaryRole;
}
public class RoleButton: Button {
protected Roles buttonRoles;
...
}
public class SharedPreRenderCommand : ICommand {
public void ExecuteOnPreRender(WebControl control, Roles roles, EventArgs args) {
}
}
Roles . , . -, , -.
... , , , .
: D
HTH,