Questions about interface related design considerations, such as programming to the interface.
-2
votes
0answers
49 views
How to improve architecture [on hold]
I've been presented with the following code and asked to improve the architecture. My thinking is going with interfaces and inheritance. Would you suggest using a design pattern? What would you ...
3
votes
1answer
58 views
Within an interface specified by a core component, should it request IReadOnlyCollection or IEnumerable?
In thinking about the principle of "be conservative in what you send and liberal in what you accept", I generally try to make my methods receive IEnumerable parameters, but emit a IReadOnlyCollection ...
0
votes
3answers
187 views
What to do if I need more than one base class in C#? [closed]
Let's say I have a grid with square fields. For the fields I have an abstract Field class. This class has several subclasses, for example EmptyField or RoadField. Some of these fields can be connected ...
2
votes
1answer
121 views
Lower class count vs explicitness
To help with an application that manipulates and works from an XML structure to produce other information, I've created a class structure that closely follows the XML structure.
So, the XML is:
...
1
vote
1answer
52 views
Package Interfaces - Coupling & Re-Usability
Intent
Packages should be designed to perform a single function well.
Ideally this means that they should be highly modular and different packages should be able to be 'plugged-in' simply by ...
3
votes
1answer
193 views
Why covariance is forbidden for abstract class in C#
I've been digging in covariance and contravariance in C# and there is one thing I could not manage to understand. C# (AFAIK, as of 4 version) allows one to declare the covariant or contravariant ...
2
votes
3answers
159 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
82 views
Use the chance to return booleans after method calls for an optional layer of exception handling? [duplicate]
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 ...
26
votes
6answers
3k 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
223 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
51 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
107 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
119 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
109 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
81 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
101 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
295 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 ...
2
votes
1answer
95 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
70 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
449 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
194 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; }
...
3
votes
6answers
160 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
344 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
144 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
151 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
221 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
377 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
110 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
434 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
137 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
312 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
328 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 ...
4
votes
1answer
128 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
205 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
81 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
135 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
115 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
237 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
142 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
73 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
407 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
154 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
178 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
335 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
321 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
79 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 ...