Tagged Questions
3
votes
2answers
221 views
Why does C# allow properties in interfaces?
In C#, the following code is valid
interface I{
int property{get;set;}
}
Which doesn't make any sense to me. This seems to break one of the most important principles of interfaces: lack of ...
0
votes
2answers
136 views
c# naming - What are common conventions for a suffix to distinguish between read-only and writable interfaces [closed]
Assume an interface that allows queries on a spatial tree
public ISpatialTree
{
int FindChildIndex(Vector point);
bool IsLeaf { get; }
ICollection<ISpatialTree> Children { get; }
}
...
5
votes
5answers
238 views
How to enforce implementation of interface to behave a certain way
Suppose you had the following interface
public interface IUserRepository
{
User GetByID(int userID);
}
How would you enforce implementers of this interface to throw an exception if a user is ...
0
votes
2answers
129 views
Interface method signature not restrictive enough
I wrote a piece of code at my job sometime ago. While writting the code I wrote few interfaces who would allow me to add more flexibility and at that time I was also trying to understand OOP concept ...
3
votes
1answer
108 views
Different scoring algorithms for different competition elements
I am creating a scoring system for a competition that is somewhat obscure, but it resembles the Olympics in terms of its high-level structure. Therefore, I will ask my question in terms of an ...
1
vote
1answer
166 views
Should I use inheritance or an interface?
So in a nutshell I have an abstract class :
public abstract class Member
{
public string PCode { get; set; }
public string Reference { get; set; }
public DateTime? ElectedDate { get; set; }
}
And ...
2
votes
2answers
113 views
Segregating interfaces/concerns to a tree
When working with a single object there are a number of ways to segregate interfaces to it.
Breaking it into smaller components that can be treated independently.
Breaking it into simpler ...
3
votes
2answers
327 views
Implementing the Interface Segregation Principle
Does this IConvertible interface satisfy the Interface Segregation Principle (ie. the "I" in SOLID)?
Here is the definition:
public interface IConvertible
{
TypeCode GetTypeCode();
bool ...
-4
votes
1answer
139 views
what is the main utility of Interface in real world programming (OOPS) [duplicate]
what is the main utility of Interface. we know that we can implement dynamic behavior using interface but i guess it is not only the utility. so i like to know when we have to write interface and when ...
4
votes
5answers
220 views
Loose coupling and shuffling dependencies
I have a bunch of classes that look something like this:
public class MyGame()
{
private Graphics graphics;
private Player player;
public MyGame()
{
graphics = new ...
8
votes
5answers
623 views
Should I write an interface API before an implementation?
I've been delving into more "organized" programming recently and I've been learning that I should be programming to an interface, not an implementation. With that in mind, would it be better to ...
1
vote
1answer
320 views
Interface Dependencies or Abstract Classes
I have a decision to make and I am wondering what would be the better solution. I am refactoring an older application and intend to really get into the nuts and bolts of it.
There are 8 report types ...
2
votes
6answers
2k views
Design Patterns - Why the need for interfaces?
OK. I am learning design patterns. Every time I see someone code an example of a design pattern they use interfaces. Here is an example:
...
1
vote
3answers
216 views
How do I support interfaces for different devices in the same input scenario?
I asked this question on SO but someone pointed out that I would be better off here. He's most likely right. So here I go!
So I just wanted an opinion. I have 2 different ways to approach the ...
2
votes
4answers
228 views
Why should IQueryProvider implementations throw NotSupportedExceptions?
Searching the web, we can find plentiful examples of various ORMs (nHibernate, EF, LinqToSql, etc.) that implement but don't actually support the full IQueryable<T> interface, throwing ...
3
votes
2answers
655 views
Collection interfaces in C#, coming from Java
In Java, I'm used to declaring collections using the most-abstract interface possible and then constructing them using the concrete implementation that makes sense at the time. It usually looks ...
1
vote
1answer
127 views
How do you distinguish your public API interfaces from the interfaces you use for testing/mocking?
Mocking frameworks are useful for creating mock objects that isolate the code under test from its surrounding software environment. Some mocking frameworks cannot mock non-virtual methods, so they ...
12
votes
5answers
1k views
What is the functional-programming alternative to an interface?
If I want to program in a "functional" style, with what would I replace an interface?
interface IFace
{
string Name { get; set; }
int Id { get; }
}
class Foo : IFace { ... }
Maybe a ...
16
votes
5answers
2k views
Use of keyword “Using” in C# interface
When I'm using C# to write some code and I define an interface using Visual Studio 2010, it always includes a number of "using" statements (as shown in the example)
using System;
using ...
3
votes
4answers
4k views
Instantiating Interfaces in C#?
I am reading/learning about interfaces in C# at the moment, and thus far I managed to understand how it differs from an abstract class. In the book I am reading the author explains that interfaces are ...
2
votes
4answers
5k views
Abstract class + Inheritance vs Interface
Hello fellow programmers,
I am reading a book on C# and the author is comparing Abstract classes and Interfaces. He claims that if you have the following "abstract class:"
abstract class ...
15
votes
10answers
2k views
Declaring interface in the same file as the base class, is it a good practice?
To be interchangable and testable, normally services with logic needs to have interface, e.g.
public class FooService: IFooService
{ ... }
Design-wise, I agree with this, but one of the things ...
7
votes
4answers
3k views
Should interfaces extend (and in doing so inherit methods of) other interfaces
Although this is a general question it is also specific to a problem I am currently experiencing. I currently have an interface specified in my solution called
public interface IContextProvider
{
...
1
vote
0answers
397 views
Understanding interfaces [duplicate]
Possible Duplicate:
When to use abstract classes instead of interfaces and extension methods in C#?
Why are interfaces useful?
What is the point of an interface?
What other reasons are ...
8
votes
4answers
2k views
Return interface or class
Suppose I have a method
public List<User> GetBatchOfUsers(IEnumerable<int> userIDs)
{
List<User> users = new List<User>();
// some database stuff
return users;
}
...
4
votes
2answers
505 views
Storing IEnumerable as instance variable - is it a code smell to expect it to change?
I have something that works like a fixed size list - it's actually called FixedSizeStack<T> in my program. I will use it to represent the X last occured events. This event list will then be ...
3
votes
4answers
1k views
How can I explain C# interfaces, and constructors to a 8 years old kid?
How can I explain C# interfaces and constructors to a 8 years old genius kid?
3
votes
4answers
299 views
As a tooling/automation developer, can I be making better use of OOP?
My time as a developer (~8 yrs) has been spent creating tooling/automation of one sort or another. The tools I develop usually interface with one or more API's. These API's could be win32, WMI, ...
8
votes
3answers
7k views
Difference between various Collection Generic Interfaces in C#
I have been playing around with C# for Windows and ASP.net MVC development for some time now. But I am still unclear on a few areas. I am trying to understand the basic difference between and ...
3
votes
4answers
2k views
What are good reasons to use explicit interface implementation for the sole purpose of hiding members?
During one of my studies into the intricacies of C#, I came across an interesting passage concerning explicit interface implementation.
While this syntax is quite helpful when you need to resolve ...
0
votes
1answer
585 views
Building a table (DataGridView) while keeping decoupled from Model
I'll try to keep this simple.
Small C# app, dialog based, one has a DataGridView.
I've got an UpdateTable function in the form that accepts a DataSet and passes it to the DataGridView.DataSource. ...
36
votes
7answers
26k views
When to use abstract classes instead of interfaces with extension methods in C#?
"Abstract class" and "interface" are similar concepts, with interface being the more abstract of the two. One differentiating factor is that abstract classes provide method implementations for derived ...