Questions about interface related design considerations, such as programming to the interface.

learn more… | top users | synonyms (1)

1
vote
3answers
237 views

Should I use an interface when methods are only similar?

I was posed with the idea of creating an object that checks if a point will collide with a line: public class PointAndLineSegmentCollisionDetector { public void Collides(Point p, LineSegment s) { ...
1
vote
2answers
1k views

Adhering to a protocol and being a subclass at the same time?

In objective C, I have a situation where I would like to have an abstract protocol (interface) with 5 methods and 4 properties, but at the same time, I'd like to have a common implementation of 3 of ...
2
votes
1answer
195 views

Use of interfaces to ease rapid development/prototypes

Recently I've started to put almost all of my data structures into interfaces, and many of the classes that contain pieces of logic code as well, depending on how much work they are. I find that this ...
10
votes
6answers
6k views

What are the differences between abstract classes, interfaces, and when to use them

Recently I have started to wrap my head around OOP, and I am now to the point where the more I read about the differences between abstract classes and interfaces the more confused I become. So far, ...
3
votes
6answers
774 views

Can interface be not abstract?

Friend of mine said that not every interface is abstract. I haven't chance to discuss that with him but it get me thinking of not abstract interface in any type of language. Is there a non abstract ...
3
votes
2answers
194 views

Developing JSON API for a Carpool Engine

I am developing a new set of API methods for carpooling/cab booking, so if a developer needs to develop an app or webportal for carpooling, he can call my JSON API. Basically making it easy for ...
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 ...
6
votes
5answers
460 views

Everything has an Interface [duplicate]

Possible Duplicate: Do I need to use an interface when only one class will ever implement it? I am taking over a project where every single real class is implementing an Interface. The ...
3
votes
4answers
5k 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 ...
13
votes
4answers
475 views

Two interfaces with identical signatures

I am attempting to model a card game where cards have two important sets of features: The first is an effect. These are the changes to the game state that happen when you play the card. The interface ...
3
votes
4answers
7k 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 ...
0
votes
2answers
228 views

Why to say, my function is of IFly type rather than saying it's Airplane type

Say, I have two classes: Airplane and Bird, both of them fly. Both implement the interface IFly. IFly declares a function StartFlying(). Thus both Airplane and Bird have to define the function, and ...
2
votes
2answers
2k views

Java - What methods to put in an interface and what to keep out

I'm designing a file handler interface: public interface FileHandler { public void openFileHandler(String fileName); public void closeFileHandler(); public String readLine(); public ...
4
votes
5answers
493 views

Should concrete classes avoid calling other concrete classes, except for data objects?

In Appendix A to The Art of Unit Testing, Roy Osherove, speaking about ways to write testable code from the start, says, An abstract class shouldn't call concrete classes, and concerete classes ...
5
votes
2answers
415 views

Function that requires many parameters

I have a problem related to this: Are there guidelines on how many parameters a function should accept? In my case, I have a function that describes a rounded rectangle. The caller specifies An ...
15
votes
10answers
3k 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 ...
1
vote
1answer
186 views

What resources are there for facial recognition [closed]

I'm interested in learning the theory behind facial recognition software so that I can hopefully implement it in the future. Not just face tracking, but being able to recognize individuals. What ...
9
votes
4answers
4k 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 { ...
10
votes
7answers
3k views

Interfaces on an abstract class

My coworker and I have different opinions on the relationship between base classes and interfaces. I'm of the belief that a class should not implement an interface unless that class can be used when ...
1
vote
0answers
486 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 ...
2
votes
1answer
8k views

Difference between spring setter and interface injection?

I know how constructor and setter injection works in spring. Normally I use interfaces instead of classes to inject beans using setter and I consider it as interface injection, but in case of ...
4
votes
3answers
141 views

What level of detail to use in an interface members descriptions?

I am extracting interfaces from some classes in .NET, and I am not completely sure about what level of detail of description to use for some of the interface members (properties, methods). An ...
9
votes
2answers
466 views

Is there an “ask for only what you need” interface principle?

I have grown into using a principle for designing and consuming interfaces that says basically, "ask for only what you need." For instance, if I have a bunch of types that can be deleted, I'll make ...
8
votes
4answers
406 views

Use cases for “private” interfaces?

I was wondering if there was a valid use case for being able to properly define the specific internal properties and functions of a class in a way similar to how an interface defines the public ...
2
votes
1answer
575 views

Why this code create object as interface?

In am reading Spring in Action (3rd edition) and here a snippet from it: ApplicationContext ctx=new ClassPathXmlApplicationContext("springidol.xml"); Performer ...
6
votes
3answers
513 views

What do you call an interface with no defining methods used as property setters

In ASP.NET and C# I've ran across this before. Your class needs to implement interface ISomething in order for something in the super class to supply something to you. I can't remember the details, ...
5
votes
2answers
148 views

Using a openid in a “closed system”

I would like to publish a website for certain family members only. Simply put, like a mishmash of family photos and videos. I want it to remain private, however. I was considering using openid for ...
8
votes
4answers
3k 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; } ...
13
votes
4answers
940 views

Is there a different usage rationale for abstract classes/interfaces in C++ and Java

According to Herb Sutter one should prefer abstract interfaces (all pure virtual functions) to abstract classes in C++ to decouple the implementation as far as possible. While I personally find this ...
72
votes
14answers
19k views

Do I need to use an interface when only one class will ever implement it?

Isn't the whole point of an interface to for multiple classes to adhere to a set of rules and implementations?
3
votes
1answer
286 views

Is this Hybrid of Interface / Composition kosher?

I'm working on a project in which I'm considering using a hybrid of interfaces and composition as a single thing. What I mean by this is having a contain*ee* class be used as a front for ...
2
votes
2answers
255 views

Need some advice on CLI design, I need to provide simple but powerful command line options

I am writing a utility that runs on RHEL5 command line. I need my command line options to be simple but powerful. I looked at the various UNIX utilities to get an idea of how simple command line ...
4
votes
2answers
542 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 ...
8
votes
9answers
1k views

What OO Design to use ( is there a Design Pattern )?

I have two objects that represent a 'Bar/Club' ( a place where you drink/socialise). In one scenario I need the bar name, address, distance, slogon In another scenario I need the bar name, address, ...
1
vote
1answer
192 views

The design of a generic data synchronizer, or, an [object] that does [actions] with the aid of [helpers]

I'd like to create a generic data-source "synchronizer," where data-source "types" may include MySQL databases, Google Spreadsheets documents, CSV files, among others. I've been trying to figure out ...
5
votes
3answers
536 views

Switching from abstract class to interface

I have an abstract class which has all abstract methods except one which constructs objects of the subclasses. Now my mentor asked me to move this abstract class to an interface. Having an interface ...
5
votes
4answers
369 views

Passing compound object for parameters

I have different data modules, which take a couple of parameters from a configuration list. Do you think it's ok to pass a configuration object as a whole module1(config) and let the module pick what ...
9
votes
4answers
876 views

Is it bad practice to use an interface for categorization only?

For example: Say I have classes A, B, C. I have two interfaces, lets call them IAnimal and IDog. IDog inherits from IAnimal. A and B are IDogs, while C is not, but it is an IAnimal. The important ...
3
votes
2answers
266 views

Is this a pattern? Proxy/delegation of interface to existing concrete implementation

I occasionally write code like this when I want to replace small parts of an existing implementation: public interface IFoo { void Bar(); } public class Foo : IFoo { public void Bar() { ...
3
votes
2answers
964 views

Is it a good programming practice to have a class with several .h files?

I suppose the class have several different interfaces. Some it shows to some class, some it shows to other classes. Are there any good reason for that? One thing I can think of is with one .h per ...
38
votes
6answers
8k views

What is the point of having every service class have an interface? [duplicate]

At the company I work at, every service class has a corresponding interface. Is this necessarily? Most of these interfaces are only used by a single class and we are not creating any sort of public ...
5
votes
5answers
4k views

How to Model a simple file-system by UML class diagram

I want to model a file system which contains both files and directories, and directories can contain either files or other directories. This is what I have reached so far: In OOSE book, however, a ...
16
votes
10answers
12k views

Why use an interface when the class can directly implement the functions? [duplicate]

Possible Duplicate: Why are interfaces useful? Like most faculty, my java faculty introduced interface without explaining or even mentioning its practical use. Now I imagine interfaces have ...
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?
6
votes
3answers
907 views

Checking preconditions or not

I've been wanting to find a solid answer to the question of whether or not to have runtime checks to validate input for the purposes of ensuring a client has stuck to their end of the agreement in ...
3
votes
4answers
312 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, ...
1
vote
6answers
421 views

Interfaces: profit of using

First of all, my ubiquitous language is PHP, and I'm thinking about learning Java. So let me split my question on two closely related parts. Here goes the first part. Say I have a domain-model ...
1
vote
4answers
2k views

Teaching java interfaces to absolute beginners: What is a good example? [duplicate]

Possible Duplicate: Explaining interfaces to beginning programmers? I searched on stackoverflow and here for a good example to teach java interfaces in a beginners class. I found the ...
14
votes
5answers
2k views

How do you evolve & version an interface?

Say you have an interface IFoo: public interface IFoo { void Bar(string s); int Quux(object o); } In version 2 of your API, you need to add a method Glarg to this interface. How do you do ...
9
votes
4answers
8k views

Who extends interfaces? And why?

AFAIK, my class extends parent classes and implements interfaces. But I run across a situation, where I can't use implements SomeInterface. It is the declaration of a generic types. For example: ...