You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The idea seems little strange, but there are various practical uses. Most of the time we implement same logic in many classes just because they are inherited from different classes. Let's assume a simple UI related logic, I want to write a OnClick tracking for couple of classes (I know, this can be done with event handlers, but its not the point, there may be classes without event handlers, non UI classes). They are TextBox, ComboBox, ListBox. Now all these classes already exist in framework. I have to create MyTextBox, MyComboBox and MyListBox.
And in each class I write same logic, ... track onclick. I create a ClickTracker class and create instance of ClickTracker as follow,
public class ClickTracker<T> where T: UIElement{
public void OnClick(T sender, EventArgs e) {
// my big implementation
}
}
public class MyTextBox: TextBox{
ClickTracker<TextBox> tracker = new ClickTracker<TextBox>();
override void OnClick(Object sender, EventArgs e){
tracker.OnClick(this,e);
}
}
public class MyComboBox: ComboBox{
ClickTracker<ComboBox> tracker = new ClickTracker<ComboBox>();
override void OnClick(Object sender, EventArgs e){
tracker.OnClick(this,e);
}
}
Not only implementation is time consuming but there is already lot of parameter passing.
If there was a way like...
// this class is volatile and can't be used without strict
// base class and it is just a placeholder, this is not a class and
// does not show up in reflection...
public volatile class ClickTracker : Control {
public override void OnClick(Object sender, EventArgs e){
// my tracking logic...
}
}
// this simply causes easy inline expansion of ClickTracker class
// look at implementation closely, MyTextBox is actually inherited from TextBox
public class MyTextBox: ClickTracker : TextBox{
}
public class MyComboBox : ClickTracker : ComboBox {
}
or we can have some alternative syntax like
public class MyTextBox: ClickTracker<TextBox>{
}
public class MyComboBox : ClickTracker<ComboBox> {
}
or
public class MyTextBox: ClickTracker(TextBox){
}
public class MyComboBox : ClickTracker(ComboBox) {
}
Volatile class properties
It does not appear in reflection
They are simply inline expansion like Macro
Implementation of volatile class requires a non volatile base class
Volatile class does not break single inheritance restriction
Reduces unnecessary shim classes
The text was updated successfully, but these errors were encountered:
Trait is different, Volatile class derives from a specific base class, allowing it to easily access all members for editing and intellisense as well as it does not allow any random base class.
neurospeech
changed the title
Volatile or Macro class with Dynamic base class
Proposal: Volatile or Macro class with Dynamic base class
Feb 19, 2016
The idea seems little strange, but there are various practical uses. Most of the time we implement same logic in many classes just because they are inherited from different classes. Let's assume a simple UI related logic, I want to write a OnClick tracking for couple of classes (I know, this can be done with event handlers, but its not the point, there may be classes without event handlers, non UI classes). They are TextBox, ComboBox, ListBox. Now all these classes already exist in framework. I have to create MyTextBox, MyComboBox and MyListBox.
And in each class I write same logic, ... track onclick. I create a ClickTracker class and create instance of ClickTracker as follow,
Not only implementation is time consuming but there is already lot of parameter passing.
If there was a way like...
or we can have some alternative syntax like
or
Volatile class properties
The text was updated successfully, but these errors were encountered: