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

learn more… | top users | synonyms (1)

8
votes
6answers
5k 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, ...
9
votes
4answers
900 views

When to use interfaces (unit testing, IoC?)

I suspect I've made a schoolboy error here, and am looking for clarification. A lot of the classes in my solution (C#) - dare I say the majority - I've ended up writing a corresponding interface for. ...
9
votes
4answers
7k 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: ...
30
votes
4answers
3k views

What did Rich Hickey mean when he said, “All that specificity [of interfaces/classes/types] kills your reuse!”

In Rich Hickey's thought-provoking goto conference keynote "The Value of Values" at 29 minutes he's talking about the overhead of a language like Java and makes a statement like, "All those interfaces ...
2
votes
2answers
1k views

Programming against a protocol in Objective-C

I stumbled accross the SOLID principles. There is one burning question. Should I always use protocols? I never saw someone using them in the way that a Java developer would use them. I tried it in a ...
7
votes
4answers
3k views

Can I consider interface methods as abstract methods?

I was thinking about that, and I had some doubts. When I declare an interface, for example: public interface MyInterface { public void method1(); public void method2(); } Could these ...
29
votes
12answers
8k views

Why does PHP have interfaces?

I noticed that as of PHP5, interfaces have been added to the language. However, since PHP is so loosely typed, it seems that most of the benefits of using interfaces is lost. Why is this included in ...
4
votes
5answers
321 views

How does the concept of a class change when passing data to the constructor instead of method parameters?

Let's say we're making a parser. One implementation could be: public sealed class Parser1 { public string Parse(string text) { ... } } Or we could pass the text to the ...
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 ...
1
vote
2answers
190 views

Violating the Interface Segregation Principle?

I currently have an interface named InternalEntityIdTransformer, which has a getInternalId method, that given an external id returns the corresponding internal one. Now I am working on functionality ...
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, ...
5
votes
3answers
513 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 ...
-1
votes
1answer
63 views

serving up future-proof kinfolk - extensible contract interfaces [closed]

Ok, I have this human here, but what can it do, how would you discover its special abilities? And when you find out what kind of expert you've got then how would you actually make use of its unique ...
1
vote
5answers
711 views

The need for adding an interface to every class [duplicate]

My coworker and I are arguing very hard about this topic. He's thinking that every single class should have an Interface that the class implements (also Single-Implementations). He uses this design ...
1
vote
3answers
198 views

Coarse grained remote interface vs encapsulating business logic

I'm writing a Web Service that will be consumed by a Mobile client. The Mobile client has to make several chained requirements checks to determine whether the user may initiate a request, and if so ...
5
votes
6answers
3k views

Is there any difference between interfaces and abstract classes that have abstract methods only?

Let's say we have an abstract class and let this class has only abstract methods. Is this abstract class different from an interface that has same methods only? What I am looking to know is if there ...
2
votes
3answers
245 views

Implicit optimization versus explicit optimization

To explain what I mean, let me start with an example. Consider a deque that supports O(logn) concatenation with another deque and O(n) addition of n elements at one end. This dequeimplements a ...
-5
votes
4answers
2k views

What is Interface in Java programming language? [duplicate]

Last week my lecturer was teaching us about interfaces in Java. However, I failed to understand her explanation that well. Does anyone have a good description, or explanation of Java interfaces, and ...
6
votes
1answer
276 views

Term for a Class with Multiple Interfaces

Say I have a class that implements multiple interfaces. I pass the same instance around using a different interface, depending on what the consumer is interested in. I am trying to remember what this ...
0
votes
1answer
73 views

OO Design: hint EntityManager to preload some datasets

say I have an EntityManager that can read(PK) a dataset from the DB and return it. I have an application that will process multiple records, iterate over them and for each, use the EntityManager to ...
2
votes
1answer
193 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 ...
4
votes
2answers
214 views

Should I make package private my DAO interfaces?

I have several DAO classes that implement an interface. In the other hand, I have Service classes that use those DAO implementations. So far all the DAO interfaces are public and I was thinking if ...
7
votes
3answers
171 views

Rules about the concreteness of method parameter types, return types and property types

Some time ago I read a kind of "rule of thumb" about the concreteness of method parameter types, return types and property types, but I just do not remember it. It said something about keep your ...
0
votes
2answers
567 views

1 Interface 2 Implementations and an EJB exception

In my JavaEE project I have an interface like this: @Local public interface DataAccess { ... } And two stateless beans implementing it: @Stateless public class DataAccess_Online implements ...
4
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 ...
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 ...
1
vote
4answers
472 views

Switch interface implementation using configuration [closed]

We want to allow the same core service to be either fully implemented or, as other option, to be a proxy toward a client legacy system (via a WSDL for example). In that way, we have both ...
1
vote
1answer
149 views

Class inheritance and extra parameters

Im trying to create an SMS gateway .. I have a request coming in from a client (web form or API or database record) that I need to process and forward on to a 3rd Party API - or SMS provider. So that ...
3
votes
1answer
279 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 ...
4
votes
1answer
207 views

Can a common interface be defined for Cartesian and Polar coordinate data?

I'm rewriting a set of file readers that a former-colleague of mine created that read raw-point data of XYZ (Cartesian) coordinates or RTZ (Polar) coordinates. Currently the data is stored directly in ...
5
votes
1answer
239 views

Why aren't there Dimension and Point interfaces?

I mean something along the lines of: public interface Dimensioned { int getWidth(); int getHeight(); } and public interface Positioned { int getX(); int getY(); } There are a ...
1
vote
3answers
229 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
1answer
181 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 ...
2
votes
3answers
117 views

Adding Methods In Addition to an Interface

Let's say I have ThingImpl and IThing. The former is an implementation of the latter, which is an interface. IThing has 1 method: do(arg1) Is it considered a hack/bad practice to add a method in ...
8
votes
3answers
1k views

Should I implement an interface directly or have the superclass do it?

Is there a difference between public class A extends AbstractB implements C {...} versus... public class A extends AbstractB {...} AbstractB implements C {...} I understand that in both cases, ...
1
vote
2answers
115 views

Interface extension

Suppose that I have an input stream interface, which defines a method for reading data. I also have a seekable interface which defines a method for seeking. A natural way of defining a input file is ...
3
votes
7answers
626 views

What problems will I face if I remove the concept of interfaces from my code?

I have been programming for many years but I am still not comfortable with the concept of "Interfaces". I try to use interfaces but many times I don't see a mandatory use for it. I think this is ...
64
votes
13answers
16k 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?
5
votes
2answers
658 views

How to create contracts in python

I am currently learning Python (from Java) and have a question on contracts. Example: an application defines an interface that all plugins must implement and then the main application can call it. ...
3
votes
6answers
665 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 ...
0
votes
0answers
131 views

Where are the Interface information stored?

I would like to know whether the information in an interface such as the variables which are final and the methods which are abstract and static would all live in method area ??? And what would be ...
2
votes
2answers
249 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 ...
1
vote
2answers
823 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 ...
3
votes
2answers
185 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 ...
4
votes
5answers
476 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 ...
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
412 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 ...
13
votes
4answers
454 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 ...
0
votes
2answers
227 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 ...
1
vote
2answers
1k 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 ...