Skip to main content

All Questions

23 votes
8 answers
73k views

What is the point of an interface? [duplicate]

Possible Duplicate: When to use abstract classes instead of interfaces and extension methods in C#? What other reasons are there to write interfaces rather than abstract classes? This question ...
hakish's user avatar
  • 463
11 votes
9 answers
5k 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, ...
Blundell's user avatar
  • 218
9 votes
4 answers
3k views

OOP Design considering no modifications to existing design

The question is: interface Animal { void eat(); } class Lion implements Animal{ public void eat(){ //do somethng } } class Test { public static void main(String[] args) { ...
beginner_coder's user avatar
9 votes
5 answers
2k views

Does it always make sense to "program to an interface" in Java?

I've seen the discussion at this question regarding how a class that implements from an interface would be instantiated. In my case, I'm writing a very small program in Java that uses an instance of ...
jimijazz's user avatar
  • 241
9 votes
4 answers
5k views

How to force "program to an interface" without using a java Interface in java 1.6

In java 1.8 they have wonderful new "default interface methods". In 1.6 how close can we come? The goal: use code to keep clients from being able to tell that a class is not a java interface. If we ...
candied_orange's user avatar
9 votes
3 answers
3k views

Is it OK for interfaces to depend on concrete classes?

I am creating interface in Java for custom error handler. Want to pass an argument error object but I need it to be child of Exception class. Is it okay to use my defined class name in an interface ?...
nikartix's user avatar
  • 259
4 votes
3 answers
1k views

Why use arg type `class Object` instead of `Comparable[]`?

In the code below, I believe it would look more appropriate to make the method argument be of type Comparable[] instead of Object[]. The first reason it would be more appropriate is that one can be ...
overexchange's user avatar
  • 2,305
4 votes
2 answers
111 views

How are settings structured when they can be configured in diffferent ways?

Suppose of this question the following: I'm in full control of this project I'm writing a media player Obviously, a media player will allow a user to adjust the volume, so I might have a class that ...
user avatar
3 votes
4 answers
10k views

Why 'List<E>' is an 'interface' but not 'abstract class'?

Amidst defining the hierarchy, firstly, one can think to embed the abstract method(behavior) in abstract class only because the derive concrete class possess that behavior as core behavior with it's ...
overexchange's user avatar
  • 2,305
3 votes
2 answers
4k views

Why we use interface since we need to implement the method in our derived class [closed]

I have read the replies from those post(Why are interfaces useful?) and (Why use an interface when the class can directly implement the functions?), which is the similar question as my this post. But ...
FullStackDeveloper's user avatar
3 votes
4 answers
515 views

Does "declare the most abstract type" increase coupling actually?

According to Why define a Java object using interface (e.g. Map) rather than implementation (HashMap), I know I should declare the most abstract type possible, so for example: public interface Fruit{ }...
wcminipgasker2023's user avatar
3 votes
5 answers
2k views

Explanation of the definition of interface inheritance as described in GoF book

I am reading the first chapter of the Gof book. Section 1.6 discusses about class vs interface inheritance: Class versus Interface Inheritance It's important to understand the difference between an ...
Geek's user avatar
  • 5,217
3 votes
1 answer
6k views

Using generics on interfaces when implementation is not generic

Is it acceptable practice to put generics on an interface when the implementation will not be generic? Lets say that my project will have many classes that read data from the database. I may make a ...
radian's user avatar
  • 103
3 votes
2 answers
179 views

Composing and Inheriting from the Same Type

To start off with an example: I have a read-only Repository used for getting arbitrary values. This behavior can be implemented multiple ways. I also want to allow opt-in mutation of the repository's ...
Mario Ishac's user avatar
2 votes
2 answers
539 views

Expressing interface inheritance in natural language [duplicate]

In object-oriented programming, when you extend a class you establish an is-a relationship between a new subtype and its parent(s), i.e. B is an A (aka code inheritance). When you compose a class with ...
zepp133's user avatar
  • 221

15 30 50 per page