Skip to main content

All Questions

2 votes
3 answers
164 views

Java design: there is two interface: B extends A. A and B have one subclass each, named ABase and BBase, can I make BBase extend ABase?

there is two interfaces A and B: public interface A { } public interface B extends A{ } A and B have one subclass each: public abstract class ABase implements A{ } public abstract class BBase ...
Guo's user avatar
  • 177
2 votes
2 answers
177 views

How to structure classes for two distinct use cases that share key parameters

I have a Java application that needs to generate mathematically-defined 3D shapes for a voxel world (Minecraft specifically, but that's not important to the discussion). These include sphere, ovoid, ...
Excrubulent's user avatar
6 votes
1 answer
2k views

Why were default methods introduced to Java?

Was introducing default methods to java inevitable? As far as I know multiple class inheritance was not introduced to avoid difficulties with the method signature clash in base classes. So we avoided ...
bridgemnc's user avatar
  • 261
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
1 vote
4 answers
1k views

Why have separate keywords for 'extends' and 'implements' in Java? [closed]

Short answer that I've come to accept: Firstly, it helps with readability, being able to see which is the superclass apart from interfaces. Secondly, though 'extends' and 'implements' do the same ...
xtratic's user avatar
  • 456
0 votes
2 answers
297 views

Classes as parameters

I would like to write a data structure implementation in Java that uses caches as a core part of its functionality, and I would like the user to be able to provide their own cache implementations that ...
user129137's user avatar
3 votes
1 answer
2k views

Is it bad practice to perform an "optional" interface inheritance?

Say... you're trying to write a networkCallback code in java: public interface NetworkCallback { void onNetworkResult1(Object object); void onNetworkFailure(Object object); } you want to use ...
lawonga's user avatar
  • 139
7 votes
2 answers
411 views

Java redeclare inherited interfaces?

While working on a small class called FractionNumber I found asking myself if I should implement an interface that I am already implementing. Sounds stupid, I know, but bear with me. My class ...
kalsowerus's user avatar
37 votes
3 answers
23k views

If I implement an Interface, is it called an Inheritance?

If my class implements an interface then can I say that I'm following inheritance? I know that when a class extends another class then it's inheritance.
Rajeev's user avatar
  • 555
11 votes
5 answers
3k views

Separate interface for mutation methods

I've been working on refactoring some code, and I think I may have taken the first step down the rabbit hole. I'm writing the example in Java, but I suppose it could be agnostic. I have an interface ...
Zymus's user avatar
  • 2,533
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
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
4 answers
6k views

Implements > extends, but what about variables?

It's preferable to write programs that depend on interfaces rather than on superclasses, but what if you want a class to have certain variables? Sometimes you want a class to implement a certain ...
Dylan Meeus'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
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