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

learn more… | top users | synonyms (1)

1
vote
3answers
135 views

When and why would you extract an abstract method from an abstract class to an interface?

I have been asked the following question in an interview: "What is the need of an interface when you can have an abstract method within an abstract class?" Which I did not know the answer to. Could ...
1
vote
1answer
80 views

Use the chance to return booleans after method calls for an optional layer of exception handling?

I would like to ask a follow-up to a question I just asked: Better to have 2 methods with clear meaning, or just 1 dual use method? I now understand why it is best to separate charge(float c); and ...
24
votes
6answers
2k views

Better to have 2 methods with clear meaning, or just 1 dual use method?

To simplify the interface, is it better to just not have the getBalance() method? Passing 0 to the charge(float c); will give the same result: public class Client { private float bal; float ...
2
votes
1answer
206 views

Open / Closed Principle

I found this code example explaining Open / Closed principle. Code before application of principle: public class Logger { public void Log(string message, LogType logType) { switch ...
0
votes
0answers
45 views

Software Architecture: CQRS and port modeling

I have a PersonComponent, which an internal implementation is based on CQRS pattern. So which one is better way to model ports (and their interfaces): I'm not totally sure that how high or low ...
0
votes
1answer
94 views

Neat way on passing interface parameter to a constructor

Having lots of Interface that needs to pass in a constructor looks messy, is there any neat way of doing it? Code snippet: public class Foo { private readonly IRepository1 _repository1; ...
-2
votes
1answer
103 views

Why are interfaces necessary in MVP design pattern?

I am trying to understands MVP using Winforms. I found this example. Why do UserModel and UserView need to implement the IUserModel and IUserView interfaces ?
1
vote
2answers
103 views

Does an interface including several methods that return instances of Object make sense?

I am in the process of writing my first true API. In the process, I am defining an interface for mapping complex data structures onto other complex data structures. At the moment, the interface ...
1
vote
2answers
74 views

Where to inject dependency required by all implementors of an interface?

I have an interface whose job is to communicate with repository (that implements some interface). It doesn't seem to make sense to implement this interface without receiving a repository,so I'd like ...
0
votes
1answer
93 views

Can I enforce the overriding of GetHashCode() and Equals() methods for users of a generic container class?

I have a container class similar to the one below (with much of the logic omitted): class Container<T> { Dictionary<T, TWrapped> contains = new Dictionary<T, TWrapper>(); ...
1
vote
3answers
285 views

How can I sell DRY? [closed]

Where I work we have around 10 VS projects in a solution which are identical in functionality (with some different different rules in a few methods) and share many exact methods. They share the same ...
1
vote
1answer
47 views

Structuring projects in a solution for interfaces

I had this idea that I would achieve some good automation and separation of concerns as follows: Define an interface, IDataProvider, in a class in a DataMuncher project that needs to both consume ...
2
votes
2answers
69 views

Where to put configuration constants?

Considering a small embedded C project, how to decide if certain constants belong to a global configuration file the header of the "module == compilation unit" on top of the the actual C file or ...
9
votes
2answers
438 views

Interface Segregation Principle: What to do if interfaces have significant overlap?

From Agile Software Development, Principles, Patterns, and Practices: Pearson New International Edition: Sometimes, the methods invoked by different groups of clients will overlap. If the overlap ...
9
votes
2answers
185 views

Programming to Data Oriented Interfaces

There is a portion of our codebase written in the following style: // IScheduledTask.cs public interface IScheduledTask { string TaskName { get; set; } int TaskPriority { get; set; } ...
-4
votes
1answer
78 views

How to determine if a type of class implements an interface [closed]

There is something I am missing about the "Type" class. I have this code: List <Type> area_space_components_sorted; public interface Igood{} Assume the list of types has 5 objects in it, and ...
3
votes
6answers
148 views

If Class is to define attributes and methods, and Interface is to define (a set of) methods, then how to think of interface needing new attributes?

I thought a class is supposed to define, or give a blueprint, of attributes and methods for an object. And then, an interface is to provide a set of methods, as a contract for its clients. (and so a ...
4
votes
2answers
341 views

How and when did it happen that, a type is an interface?

I came from a highly functional and procedural background in programming, and never knew that a type is the same as an interface. As in the Design Patterns book by GoF, it says: A type is a name ...
21
votes
5answers
1k views

Implementing an interface when you don't need one of the properties

Pretty straight-forward. I'm implementing an interface, but there's one property that is unnecessary for this class and, in fact, shouldn't be used. My initial idea was to just do something like: int ...
1
vote
1answer
141 views

When should interface be owned by client?

In Agile Software Development: Principles, Patterns, and Practices, Uncle Bob talks about client owning the service interface. My questions are : Should client always own the interface or only ...
2
votes
3answers
141 views

What is the purpose of a wrapper class that does nothing but delegate to the object it wraps?

The specific example I have in mind is javax.servlet.ServletResponseWrapper: public class ServletResponseWrapper implements ServletResponse { private ServletResponse response; /** * The ...
3
votes
3answers
204 views

How to “program to an interface”

I've read these questions: Understanding "programming to an interface" What is the point of an interface? Does it always make sense to "program to an interface" in Java? I ...
0
votes
4answers
375 views

In C#, what is the benefit of assigning a class variable to an interface variable before calling any methods?

Where I work we develop in C# .NET and I was looking a code that they have made (my job is to optimize it) but I saw something in particular: Assuming that InterfaceDHO is an interface and ClassDHO ...
0
votes
2answers
109 views

Best practice for encapsulating a parameter that requires multiple interfaces to be implemented

I encounter this issue multiple times, but I'm never sure how best to deal with it. Basically, some methods I write require the implementing object to support multiple interfaces. The example I have ...
3
votes
3answers
363 views

Generics vs common interface?

I don't remember when I wrote generic class last time. Every time I think I need it after some thinking I make a conclusion I don't. The second answer to this question made me to ask for ...
3
votes
3answers
132 views

Communicating to an Object from another without coupling in java?

So I have a Person object, and a GumballMachine object. The behavior I'm searching for is, in the intent to avoid unnecessary coupling, have the method insertCoin() called from within the Person ...
4
votes
3answers
277 views

Composition over inheritance but

I'm trying to teach myself software engineering and coming up against some conflicting information which is confusing me. I've been learning OOP and what abstract classes / Interfaces are and how to ...
3
votes
2answers
215 views

Should the main method be separate in a separate class? [closed]

In Java main methods often do little more than parsing the command line arguments and initializing an object that then takes over, for example: public class FooServer { // ... public static ...
0
votes
0answers
63 views

generic inventory system that can be used by many types of inventory systems

I would like to write code that can be used for inventory control. The initial requirement is simple, but I would like to write it generic, in case the requirements expand, the code be ready for it. ...
4
votes
1answer
96 views

UML: Should an asynchronous request-response message exchange be modelled as two ports/interfaces or one

I want to model an asynchronous request-response message exchange in UML. The request is sent from a client to a server. The server responses asynchronously. This can be modelled in a component ...
0
votes
0answers
25 views

Text based command/interface design

When using inter-process communication (pipes, memory streams, ...), I typically have a byte stream to communicate, also with http (unless using some heavy-weight web framework), the body comes as a ...
1
vote
2answers
202 views

To god (class) or not to god? [duplicate]

I'm working on a project that requires several different users in the system, all of which have overlapping responsibilities; we've isolated two possible ways of tackling this problem, but we're ...
0
votes
1answer
76 views

When designing input interfaces for a library, when to use data class rather than data interface?

Let's say library A, B and C are all custom math libraries. They may or may not use the same data types. The libraries have methods that accept data type inputs like ProcessAsync(DataTypeA) or ...
1
vote
1answer
133 views

Interface Design: Specific vs General parameter (A Minimal design vs anticipated use variation)

Code public interface IVehicle { string VehicleMake { get; } int MonthsSincePurchase { get; } bool IsApprovedUsed { get; } ... } public class WarrantyPopUpHandler { virtual bool ...
-3
votes
1answer
106 views

Why can't I return an implementation of an interface for a method that requests the interface? [closed]

I am implementing an interface I on a class A. Class A implements I. I have an Iterator T that is supposed to return an object which implements I everytime I call next. My iterator goes as follows ...
1
vote
2answers
224 views

What are the justifications for annotations in a programming language? [closed]

After spending a great deal of time writing C# and looking at Java, it seems to me that annotations are just an ugly code smell that introduce another conceptual layer that could easily be replaced by ...
0
votes
1answer
135 views

Coding to an interface vs more generic interfaces

I have a number of classes (and interfaces) which 'code to an interface' interface File { ... } interface FileConverter { public function convert(File $file); //coding to an interface ...
2
votes
1answer
70 views

Reusing an interface or method chaining

I am learning about coding to an interface in OOP programming. I understand you should code to an interface so you can 'swap out' functionality. However, I have a situation where I feel I can reuse ...
0
votes
4answers
315 views

How is an interface used in Dependency Injection?

I'm working on a simple DI library, and on the subject of using services through interfaces, I can't find the usefulness. Perhaps it's because I dont fully or properly understand how an interface ...
2
votes
1answer
151 views

Using own ArrayList in general purpose C libraries, but allowing a different implementation

I've written a couple of libraries since beginning to use C again last year. One thing that still needs addressing in both of these is the correct use of array-based lists - hereafter, ArrayLists. At ...
1
vote
1answer
59 views

MVC .NET APP Program Structure [closed]

I am just building a MVC .NET application, eventually this will use entity framework and the repository pattern to structure the program. The first release however will only be calling other jobs that ...
1
vote
2answers
165 views

Better application design - where to place interfaces

Where to place interfaces in a typical multi-layered app with DataAccess, BusinessLogic and an Endpoint modules? I propose 2 options In both cases there's only dependency from abstractions, but in ...
2
votes
3answers
308 views

Manual Dependency Injection Examples Still Tightly Coupled

I've been using AutoFac for some time now to take care of the dependency injection we're using in a web project. All is well, but I now want to demonstrate DI outside of an AutoFac context for reasons ...
0
votes
1answer
39 views

How do I use type assertions in Go when returning an interface type?

A struct I'm working on called fieldDefinition holds metadata about a field used by an object in my web app. One of the fields on fieldDefinition (it does get a bit confusing) looks something like ...
4
votes
4answers
311 views

Should an application configuration interface be broken into multiple interfaces to reduce feature creep?

My windows service is neatly separated into 5 components - each with their own interface and pulled together by a bootstrapper. One of my requirements is to provide configuration options in my ...
0
votes
1answer
77 views

Should I separate the interface or use single one [closed]

I'm developing a game, I will generate objects. I have create an interface called IObject which has the following properties: String tag // Tag for the object Vector3 position // Where the element is ...
3
votes
4answers
284 views

Design: Lisp (or other scripting language) as an interactive interface for C++?

I'm working on a medium size C++ project (will probably end up around 50k lines) and I have to provide an interactive terminal interface. The program produces scientific data as an output and the ...
1
vote
2answers
150 views

Could changing the return type from void to string introduce breaking changes?

This SDK have an interface like this: public interface Contract { void update(..); void action(..); void delete(..); } Now, we need to change it to something like this: public ...
3
votes
4answers
176 views

Design strategy for wrapping exceptions

I'm implementing a type of Repository for a framework/library that has (roughly) the following: public interface FooRepository { boolean contains(String id); Foo fetch(String id); void ...
1
vote
1answer
153 views

Inefficient use of interfaces in OOP (C#)

In my code, I've got two interfaces, let's say IOpenable and IExaminable. IOpenable allows the user to Open or Close the object, and IExaminable allows the user to Examine the object. Now, we have ...