Questions about interface related design considerations, such as programming to the interface.
0
votes
1answer
65 views
Domain-specific Interfaces
Are there any real benefits of using interfaces over abstract classes in a domain model? Does anyone have any experience using interfaces in a domain model in a real project?
From a technical ...
3
votes
2answers
215 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 ...
1
vote
2answers
96 views
Should an abstract class always abstract its methods to an interface?
I had learned sometime ago that abstract classes should always abstract their functions to an interface. So instead of having something like this -
abstract class a{
public int i;
public int ...
2
votes
0answers
55 views
Designing module interfaces
I'm studying software engineering and one thing I'm really trying to improve is my skill in software architecture. My question is quite broad, so I'll try to explain it with an example.
Suppose you ...
2
votes
2answers
242 views
Does it make sense to use interfaces if you don't have polymorphism?
Suppose I have distinct classes that have the same behavior, which can be represented like this:
public interface Behavior {
void operationA();
}
public class ImplementerA implements Behavior {
...
1
vote
2answers
84 views
How specific should be an interface about its implementation details?
Perhaps I should have picked a better title, but anyway...
Basically what to do with two or more implementations that have the same public interface, but they are meant for slightly different ...
3
votes
3answers
427 views
Why not apply Interface Segregation Principle to “extreme”
Providing that clients would typically consume just one method, though methods would be conceptually related, why not always apply the Interface Segregation Principle to the extreme and have [many] ...
39
votes
9answers
4k views
Programming for future use of interfaces
I have a colleague sitting next to me who designed an interface like this:
public interface IEventGetter {
public List<FooType> getFooList(String fooName, Date start, Date end)
...
2
votes
1answer
154 views
Code re-use in C++, via multiple inheritance or composition? Or…?
I originally asked this question on StackOverflow, but I was directed here, and I think my problem is perhaps as much conceptual as technical, so here goes.
If you’re defining a hierarchy of abstract ...
0
votes
3answers
277 views
Why do APIs generally consist of interfaces? [duplicate]
I am starting out in Java API design and in reading existing code bases, I have found that most APIs consist of interfaces only with their implementations bundled in a different package.
Having read ...
6
votes
4answers
451 views
Split up large interfaces
I'm using a large interface with about 50 methods to access a database. The interface has been written by a colleague of mine. We discussed this:
Me: 50 methods is too much. It's a code smell.
...
2
votes
0answers
68 views
The inheritance argument of zope.interface (providedby vs isinstance)
What limitations does inheritance of an interface through an abstract base class present that are addressed by zope.interface?
In the following talk given in 2010 by Jeff Rush about interfaces, at ...
1
vote
4answers
217 views
Combinatorial explosion of interfaces: How many is too many?
I'm a relative newcomer to OOP, and I'm having a bit of trouble creating good designs when it comes to interfaces.
Consider a class A with N public methods. There are a number of other classes, B, C, ...
1
vote
2answers
66 views
Creating an Interface To a Language's Standard Library?
In the process of learning test-driven development, I've been introduced to dependency injection and the use of interfaces, and have started using these concepts in my own PHP code in order to make it ...
5
votes
1answer
69 views
Designing communications for extensibility
I am working on the design stages of an application that will a) collect data from various sources (in my case that's scientific data from serial ports), keeping track of the age of the data, b) ...
0
votes
2answers
132 views
Java best practice Interface - subclasses and constants
In the case where a couple of classes implements an interface, and those classes have a couple of constants in common (but no functions), were should I put this constant ?
I've had this problem a ...
2
votes
2answers
115 views
Design for an interface implementation that provides additional functionality
There is a design problem that I came upon while implementing an interface:
Let's say there is a Device interface that promises to provide functionalities PerformA() and GetB(). This interface will ...
0
votes
1answer
97 views
Should interface only be used for behavior and not to show logical data grouped together? [duplicate]
Should an interface only be used to specify certain behavior? Would it be wrong to use interface to group logically related data?
To me it looks like we should not use interface to group logically ...
0
votes
2answers
137 views
Is using interfaces on internal code a good idea? [duplicate]
I'm working on a set of automated tests that we use internally at work. Lately, we've been designing classes that implement interfaces in addition to inheritance.
As I understand it, interfaces in ...
7
votes
2answers
261 views
How to hide AOP implementation dependency without breaking encapsulation?
I have the concept of a SlowLoading thing:
public interface SlowLoading {
boolean hasLoaded();
}
I also have a component MyComponent:
public interface myComponent{
void doSomething();
}
My ...
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; }
}
...
2
votes
1answer
91 views
Interface hierarchy design for separate domains
There are businesses and people. People could be liked and businesses could be commented on:
class Like
class Comment
class Person implements iLikeTarget
class Business implements iCommentTarget
...
5
votes
5answers
235 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 ...
13
votes
3answers
649 views
Why are interfaces more helpful than superclasses in achieving loose coupling?
(For the purpose of this question, when I say 'interface' I mean the language construct interface, and not an 'interface' in the other sense of the word, i.e. the public methods a class offers the ...
3
votes
1answer
106 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 ...
3
votes
2answers
168 views
How to manage memory in C interface for C++ implementation considering c++11?
I have a library implemented in C++ which has a C interface. This C interface is, for all intents and purposes, the only way to use this library. C++11 seems to discourage the use of raw pointers but ...
1
vote
1answer
164 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 ...
1
vote
3answers
132 views
Empty superclass for Collection of derived classes
Basically, what I would like to obtain is a way to iterate through ONE list, and call methods specific to the interface the objects in the collection implement.
In my Java project, it would result in ...
0
votes
2answers
86 views
UML Class Diagram: Abstract or Interface?
I am modeling a class diagram and have spotted an opportunity to simplify it slightly. What I want to know is, would this it be better to implement an abstract class or an interface?
The scenario is ...
1
vote
2answers
260 views
Go-like interfaces + multi-methods make sense?
Thinking about the design of a potential new language, I wonder how related are the concepts of built a OO similar to GO interfaces and multi-methods (I get this from ...
0
votes
1answer
94 views
When is it suitable to use inheritance [duplicate]
I recently had a small "argument" about inheritance with a friend. I think people overuse it a lot. Intuition tells me that that the only good reason for class inheritance is polymorphism - when there ...
0
votes
1answer
91 views
Can a Java interface declaration enforce parameter properties?
As far as I know, declaring an interface is like so:
public interface Roots_Squares {
public double square_root( double value );
}
Now... how do you enforce value to have non-negative values? ...
0
votes
3answers
179 views
Necessity of Interfaces for Small Projects
Is it necessary to use interfaces for small projects? I work at a shop writing small custom applications for clients, primarily data manipulation. I'm mostly self-taught but also took some programming ...
2
votes
2answers
111 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 ...
1
vote
3answers
246 views
Why are inheritance and interfaces restricted to instance members?
Disclaimer: I think the rules are almost the same in most OO languages, but since I'm most familiar with C# I'll be relating to this specific language.
I think that the use of attributes and ...
0
votes
3answers
132 views
Is declaring STL variables in a class definition too revealing?
If you are trying to hide implementation, would declaring STL variables be too revealing?
// in Word_Bucket.h
class Word_Bucket {
private:
std::vector<std::string> contents;
...etc
}
...
0
votes
1answer
164 views
How to use namespaces to separate interface from implementation, in c++?
As far as I can tell, you can make your interface known to others by providing your .h file. Your .cpp is the implementation. Then they can see the function names, the parameter types, the return ...
3
votes
2answers
322 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 ...
0
votes
1answer
53 views
Inverse of Extract Interface refactoring
I'm working with a Java project that has several interfaces, many of which have only one implementation. (See related question)
For a given revision of the software, one could think this acceptable ...
0
votes
0answers
40 views
What should I do with too much interfaces needed for a dialog
Let me start by doing a small summary of the changes we did in our code in the last year. We have a software (VERY big) that is used to visualize multiples underground networks, enter data in the ...
45
votes
10answers
5k views
Is better Show() + Hide() or SetVisible(bool visible)?
What is better and why? (From interface-design point of view) :
a) To have two Show() and Hide() functions
b) To have one SetVisible(bool visible) function
EDIT: For example some object have ...
4
votes
3answers
2k views
Why were default and static methods added to interfaces in Java 8 when we already had abstract classes?
In Java 8, interfaces can contain implemented methods, static methods, and the so-called "default" methods (which the implementing classes do not need to override).
In my (probably naive) view, there ...
2
votes
4answers
302 views
Understanding “programming to an interface”
I have come across the term "programming to an interface instead of an implementation" a lot, and I think I kind of understand what it means. But I want to make sure I understand it's benefits and ...
-1
votes
3answers
207 views
Regarding interfaces of classes in OOP
When one says "a class' interface":
Does he/she refer to all of the get and set methods - or do they refer only to the methods' signatures and return types, without the inner implementation of these ...
0
votes
2answers
113 views
Using interfaces as part of encapsulation
I'm creating interfaces for a number of our existing classes for mocking reasons. Many of these classes also have package scope methods as an attempt to give some level of encapsulation by ensuring ...
0
votes
1answer
348 views
Does it make sense to break fluid interface if a bad argument is passed?
If I chain some setters together and one of them does not return $this, then I will get a fatal error. But maybe that is a good thing.
$object = new object();
...
-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 ...
-1
votes
1answer
30 views
delivering ebook throught mobile app [closed]
I have designed the interface of a mag app which would deliver digitized magazine in the size of A3 paper to the mobile phone.
My choice of fileformat is jpg of each of the pages, but is there any ...
0
votes
0answers
48 views
Use Objective-C protocols like Java interfaces [duplicate]
I'm a Java developer moving to Objective-C.
So far in Objective-C I've seen protocols used extensively to implement the delegate pattern, but I haven't seen then to add a layer of abstraction in the ...