Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am currently trying to implement a marker interface in c#. But I haven't done this so far so I'd like to ask you for advice please.
Short my problem:
I've a interface Factory, and the factory contains several subinterface which should be marker interface because they don't have a property or method or something. So the marker interface should implement the interface factory. And my marker interface is for example for Cars, Trucks etc. And the marker interface is implemented for Cars for MyBMW, MyAUDI etc. How can I implement such a pattern? Thanks!
interface Factory
{
string[] process (string [] entry);
}
You should think about using Attributes instead of interface to mark classes.
then you can decide in your code how to handle specific instances as the attribute is set.
I believe you want to implent the factory pattern. I suggest you to look an example here:
http://en.wikipedia.org/wiki/Factory_method_pattern
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
We Have following interface which contains some methods.
interface MyInterface
{
string FirstName();
string LastName();
string City();
string Location();
}
and this interface we have implemented in our required classes. However, We want to implement Location method only in specific class and not in others. So, which will be the best way to achieve this.
We have tried like below
Create Interface with common methods.
Create abstract class and implement interface in it
Write specific method in abstract class as Virtual
Then override the method in actual class
But the problem here is implementation for other method is going in abstract class and not in the implementation class where we wants it.
Whichever the way we are going to achieve this it has to be same for all classes.
Any help on this appreciated.
Separate your 'MyInterface' into 2 Interfaces and for all classes you don't want the City method they will implement the one without the city method ,example:
interface MyInterface1
{
string FirstName();
string LastName();
string City();
}
interface MyInterface2 : MyInterface1
{
string Location();
}
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
Hi guys I'm trying to learn some interface. I got the basic knowledge about it, that is a contract for a class. I am a bit confused now about Interface being a data type.
Question:
What is the Purpose of using an Interface as a Data Type?
Ex.
IEnumerable Folders {get;}
or
IComparable Compare {get;}
If I'm correct then IEnumerable is also an Interface.
Where is the Value Type saved (if there is any)?
It means that the data type can reference any object of a class implementing the interface.
IEnumerable thing = new List(); works
IEnumerable thing = new Collection(); also works
IEnumerable thing = new HashSet(); also works
In any case, you don't need to know the exact type that is actually assigned to your object, you just want any type that implements the contract
For example, all IEnumerator implement GetEnumerator() which allow you to use foreach
foreach (var elem in thing) will work whatever type is thing, it just needs to implement IEnumerator.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Was going through this code here
The code here confused me
private void sendMessage()
{
IConnectionFactory wlsConnectionFactory;
IQueue ordersQueue;
IDictionary<string, Object> environment;
IContext jndiContext;
In dot net and C# a I prefix means a Interface no ?
If the above statement is true what does this line mean for example
IQueue ordersQueue;
Would this program have worked if we had something like
Queue ordersQueue instead of IQueue ordersQueue ?
First of all, an I prefix implies an interface, but that's just a convention (albeit, a extreme widely-used convention)
IQueue ordersQueue;
means that ordersQueue can be assign any type which implements the IQueue interface.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have a problem with a class that is to spawn instances containing one out of about 30 objects of different types (I call it out_out_of_many_types_of_subcontract in the code snippet below).
class supercontract
{
void supercontract (float date, one_out_of_many_types_of_subcontract subcontract)
{
stuff....
}
}
Is there any way of declaring a semi-generic variable or must I (1) resort to polymorphism between constructors or (2) casting an object as a certain type with a block of (else)if clauses?
Cheers!
I would make them all implement a single interface.
interface IContract{}
class AContract: IContract {...}
Even if the interface is empty you can limit what types could be passed to your method.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
How an Interface like IEnumerable or IQuerable can store data into itself?
or for example where this Tables go on `IQueryable?
and How can I have an Interface like that for myself ?
public Interface IMyNumerator<T>
{
}
IMyNumerator<int> mynumbers;
how can I fill mynumbers with some Int values ??
The interfaces themselves do not contain data. Although you may see IEnumerable as a type when using a collection, the underlying object is always of a specific type implementing this interface.
The object actually containing your data may be of any type implementing that interface.
Please refer to:
IEnumerable interface
List implementation
And if you would like to implement your own version of IEnumerable, inherit from the interface . Try searching for "A Beginners Tutorial on Implementing IEnumerable" on codeproject ;-)
An interface never stores data. An implementation does. Whenever your code sees an object of type IEnumerable, its actual dynamic type is something else, like a ListIterator or so. If you want to have your own type implement IEnumerable you can just do that. Usually, you'll have an embedded (private) class that implements the enumerator for a collection, though.
Interfaces define, well interfaces.
You can see it as defining a Contract, that explains how to work with a specific concept. Behind the interface is an actual Implementation, for example a Database Connection.
In computer science, an interface is the point of interaction with software
To make it a bit more simple, consider this in the hardware world.
USB defines an interface to things, it has a specific shape so it can go into a specific plug, and it has "protocols" of how to talk with a USB device.
An behind this "interface" you can have, just about any device. Fx. a camera or a storage device.
Well this is a very confusing question but I'll try anyway.
IEnumerable is an Interface that only describes public methods / properties, it does not describe how data is stored.
The implementer of this interface is responsible to store the data and can do so in any structure that suits the need.
You can have an interface like that by yourself by either implemented it or defining another interface that you use.