|
|
AVOID using marker interfaces (interfaces with no members).
If you need to mark a class as having a specific characteristic (marker), in general, use a custom attribute rather than an interface.
But who cares about the framework design guidelines?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Except marker interface can be used as constraints in generics...attributes can't.
|
|
|
|
|
yeah, what good does it do, to constrain on empty interface?!
|
|
|
|
|
I think something like Serializable has a meaning to it, so that is a different case. Needing an empty interface just so you can write generic code makes your code base stank. Since these are using in multi-thousand line files, I guess it's only one bit of the problem, but I did say that I was going to skip all the particulars and get strait to the point.
Elephant elephant elephant, sunshine sunshine sunshine
|
|
|
|
|
I once used a marker interface for some third party component.
The component COULD edit, save, cancel, delete, etc. (through a method named DoAction(string)). If an action was supported was decided by some method ActionSupported(string) or some such.
I created an empty marker interface IThirdPartyComponent, and then interfaces like ISave (with Save method), IEdit (with Edit method) etc. that all inherited IThirdPartyComponent.
That worked a lot better than DoAction(string) and ActionSupported(string), especially since I was able to built some strong typed additional tooling around it
|
|
|
|
|
I think I short circuited my own post by "I'll leave out the goodness and just get to the point". It's possible that this is the marker pattern, although it's not - it's more likely it wasn't intentionally any pattern, just something thrown in to get it working. It's hard to tell though, in the multi-thousand line code files that I'm digging through.
Also, the marker pattern seems to imply[^]
I would argue first-off that Serializable and Cloneable are bad examples of marker interfaces. Sure, they're interfaces with methods, but they imply methods, such as writeObject(ObjectOutputStream). (The compiler will create a writeObject(ObjectOutputStream) method for you if you don't override it, and all objects already have clone(), but the compiler will again create a real clone() method for you but with caveats. Both of these are weird edge cases that really aren't good design examples.)
something like meta-data[^] or methods in many cases.
1) Looking carefully on marker interface in Java e.g. Serializable, Clonnable and Remote it looks they are used to indicate something to compiler or JVM. So if JVM sees a Class is Serializable it done some special operation on it, similar way if JVM sees one Class is implement Clonnable it performs some operation to support cloning. Same is true for RMI and Remote interface. So in short Marker interface indicate, signal or a command to Compiler or JVM.
Read more: http://javarevisited.blogspot.com/2012/01/what-is-marker-interfaces-in-java-and.html#ixzz4Esj4dLCe
I don't feel like what was done here is a good use for that, especially in the junk it's tied up in. If it was intentional, it was done to avoid a good refactor in a steaming pile.
Elephant elephant elephant, sunshine sunshine sunshine
|
|
|
|
|
What component? That single DoAction method is a horrible design, and any component that uses such patterns goes straight into the trash, never to be looked at or used again.
What do you get when you cross a joke with a rhetorical question?
The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism.
Do questions with multiple question marks annoy you???
|
|
|
|
|
It was part of the DevExpress WinForms controls.
It's really not THAT horrible as you have little choice but to use string codes for your UI.
So basically there was this button bar and whenever you clicked a button some component would raise DoAction(string).
I simply wrote a custom component that translated DoAction(string) to Save, Edit, etc.
|
|
|
|
|
I use DevExpress Winforms controls and have never seen that method on any of them.
What do you get when you cross a joke with a rhetorical question?
The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism.
Do questions with multiple question marks annoy you???
|
|
|
|
|
I don't work for that company anymore, so I haven't done WinForms or DevExpress in a while, but there was this navigation button bar control to which you could hook some IIDontRememberWhat. It was that interface which had the method
|
|
|
|
|
Located the interface (INavigatableControl) and the method now takes a NavigatorButtonType enum as the parameter.
At least it isn't stringly typed anymore.
What do you get when you cross a joke with a rhetorical question?
The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism.
Do questions with multiple question marks annoy you???
|
|
|
|
|
In a Project I had to use Marker Interfaces to make base-class varialbes for MEF Imports/Exports "handlable" - some MEF (ManagedExtensibilityFramework) in your Project?
|
|
|
|
|
You could spend all that time defining a way to use JIRA to slow down work, and get more credit and would be easier
|
|
|
|
|
I'm not sure what you're getting at? We use JIRA to make things easier ? I don't really care about gettin credit. I mean, everyone likes credit or being noticed, but I just like to code.
Ravichanadeepakarandescarar wrote: use JIRA to slow down work,
JIRA is a good tool !?!
Elephant elephant elephant, sunshine sunshine sunshine
|
|
|
|
|
It all depends on the process flow and reduce the number of swivel chairs to reduce siloing resulting from diverged non-constrained islands of excellence as opposed to organization encompassing SME confluences.
|
|
|
|
|
yeah, you sound pretty familiar. I see you just joined.
Elephant elephant elephant, sunshine sunshine sunshine
|
|
|
|
|
Quote: I'm trying to figure out how some code wires up...
Quote: ...there's an empty interface...
Quote:...Because all this stuff implements this interface... I tell you this. You need subtle knowledge to understand it. Meditate, Hummmmmmm
modified 31-Jul-16 18:47pm.
|
|
|
|
|
I found a novel (or at least weird and wonderful) way to avoid recursion when traversing the nodes in a TreeView.
Here's a teaser:
System.Windows.Forms.TreeNode nod = this.tvMain.SelectedNode as System.Windows.Forms.TreeNode ;
System.Collections.Generic.Stack<System.Collections.IEnumerator> sub =
new System.Collections.Generic.Stack<System.Collections.IEnumerator>() ;
sub.Push ( nod.Nodes.GetEnumerator() ) ;
Stay tuned for an article.
|
|
|
|
|
I see where this is coming!
One can say it's inspired by the way way assembly works! :P
But the important question: does it blend? Err... I mean.. is it fast?
|
|
|
|
|
Is it anything like this extension method[^]?
What do you get when you cross a joke with a rhetorical question?
The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism.
Do questions with multiple question marks annoy you???
|
|
|
|
|
Only in how it works; not in what it does.
I don't think that will work with TreeNodes because TreeNodes are not themselves IEnumerable and the Nodes property is a non-generic IEnumerable.
I can't even add that finally because IEnumerator (the non-generic one) is not IDisposable.
The Nodes Property also has the benefit of never being null, and the TreeNodeCollection has a Count Property.
What I'm doing also needs to know the stack depth for each Node.
There are other things that are unique to what I'm doing that a general method like that is unlikely to support.
And mine uses only one while loop and one Peek. Why are they so wasteful?
And, yes, I made an Extension Method for TreeNodes -- it's an alternative to ToString() .
Thanks for showing me that.
Interesting to see that I'm not the only one to think of this technique.
Hey, that one doesn't yield the root object? I think it needs work.
|
|
|
|
|
A quick manual trace and it adds the root IEnumerator and then enumerates it, yielding the objects. Then is goes on to get more enumerators.
It is used here[^] to flatten a directory tree to a list of files and folders.
What do you get when you cross a joke with a rhetorical question?
The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism.
Do questions with multiple question marks annoy you???
|
|
|
|
|
Yes, the enumerator of the root, but not the root itself.
|
|
|
|
|
PIEBALDconsult wrote: System.Windows.Forms.TreeNode nod = this.tvMain.SelectedNode as System.Windows.Forms.TreeNode ; Why do you complain? That cast is really safe, isn't it?
And I am nod ding my head for his great capabilities in naming of variables.
|
|
|
|