Questions tagged [abstract-class]
An abstract class is a class that cannot be instantiated. They are generally meant to be extended/subclasses and generally have "abstract methods" that must be implement by subclasses.
126
questions
3
votes
2
answers
1k
views
Is expecting the API user to implement an UnsupportedOperationException okay?
I'm writing a handler for download/import of data. After inserting data to the database, several import jobs can be called, but usually it is just one. So there are two methods to get the import job(s)...
3
votes
2
answers
6k
views
Abstract classes and constants
I have two classes that share a lot of code and are conceptually variations on a common class. So I want an abstract class that contains all their common code and then they can each inherit from it ...
3
votes
2
answers
132
views
Is there any well known concern about having abstract class with few abstract methods? [closed]
I've been asked to explain why it may be bad to have an abstract class that implements most of the methods (as an extreme case, only one abstract method) and has many sub-classes.
Apart from having ...
3
votes
1
answer
675
views
Skeletal/Abstract class just to store shared state?
Given an interface for the Strategy pattern like so:
public interface Strategy {
public Output execute(Input input);
public Output getLastExecutionOutput();
}
if I want to store the last ...
3
votes
2
answers
10k
views
Building a database class in PHP
I wonder if I should write a database class for my application, and if so, how to accomplish it?
Over there on SO, a guy mentioned it should be written as an abstract class. However, I can't ...
3
votes
1
answer
4k
views
Should an abstract class implement an interface, as opposed to defining its own abstract methods?
I'm defining a class structure for persisting to our cassandra database, and I'm unsure about using a combination of an abstract class and an interface. I have two concrete classes, one for persisting ...
3
votes
1
answer
431
views
Design Patterns: Factory Pattern Vs. getInstance Inside Abstract Class
I'm working on an app where we need to use different authentication flows depending on how the user is accessing the app. I want to make sure that there is only one instance of the authentication ...
3
votes
1
answer
10k
views
Unit testing abstract classes with Google mock (gmock/gtest) (C++)
I want to test an abstract class with:
Pure virtual methods that should be overridden in sub-classes
Non-pure virtual methods that use the pure virtual methods (as opposed to this question)
class Fu
...
3
votes
1
answer
501
views
Best design for classes that draw objects but do not inherit from JPanel
I'm doing the exercise 10.1, page 476 from the book Java: How To Program, Early Objects by Paul and Harvey Deitel (10th Edition).
Modify the MyLine, MyOval and MyRectangle classes of GUI to create ...
2
votes
4
answers
9k
views
Force Derived Class to Implement Static Method C#
So the situation is like, I have few classes, all of which have a standard CRUD methods but static. I want to create a base class which will be inherited so that it can force to implement this CRUD ...
2
votes
6
answers
861
views
What is the best design decision approach?
I have two classes (named MyFoo1 and MyFoo2) that share some common functionality. So far, it does not seem like I need any polymorphic inheritance but, at this point, I am considering the following ...
2
votes
4
answers
1k
views
My concrete classes only have a constructor. Everything else comes from an abstract class. Is this bad practice?
I think that I've taken the Open-Closed and Single Responsibility principles too far. Previously, I had one huge static class containing every method that has C# talk to stored procedures on my SQL ...
2
votes
5
answers
6k
views
Should abstract classes be used to prevent instantiation
Is preventing the instantiation of a class a valid reason to make it abstract? For example, if I have a class called Gauge which has subclasses HeadingIndicator and AirSpeedIndicator, is it a good ...
2
votes
3
answers
961
views
C++ Is it okay to use nested classes as a way to namespace derived classes?
I have many abstract classes that describe many abstract ideas and objects. These classes have many complex relationships with each other, and I realize that while writing code with some of the ...
2
votes
3
answers
2k
views
How to represent the following scenario in a class diagram?
Consider a store with multiple branches and a system generates reports for each branch monthly and annually and an overall report as well monthly and annually.
So in total there are 4 types of ...
2
votes
2
answers
760
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
3
answers
990
views
How to decide, should I put methods to abstract class or to interface?
I'm writing an app it needs to have generic registration step item. It needs to be able to do some specific things (I use interface for that) and it needs to be a visual element (of Xamarin. It doesn'...
2
votes
2
answers
898
views
Is there a best practice to forward method overrides while enforcing method execution?
Sometimes i have code along the lines of this:
public abstract class A
{
protected abstract void DoSomething();
}
public abstract class B : A
{
/// <...
2
votes
3
answers
2k
views
When not to use an abstract super class?
Is there a use case/necessity (from design or implementation perspective) not to make a super class abstract?
Are there any differences in the programming language in use?
To make an example:
...
2
votes
1
answer
176
views
How valuable is decoupling in proprietary software?
When developing with Symfony2 PHP framework I often see reccomendations to decouple code but most of the time that is accompanied by a 'if you want to release as a third party bundle'.
Which begs the ...
2
votes
1
answer
2k
views
How to avoid the static_cast/dynamic_cast in `Abstract Factory` design pattern?
We are using Abstract Factory design pattern in our project, as the project became complex, most of the time the concrete class functionality need to separate to multiple class.
As the following code ...
2
votes
2
answers
1k
views
observer class as instance
Sometimes I read in observer-pattern descriptions, to make the constructor of a observer base class protected so the class will be abstract. but by making the constructor public (if even one is ...
2
votes
2
answers
140
views
OOP Best practices: Is there any reason to separate out Factory functionality from an abstract base class?
Consider the following python3 code:
from abc import ABC, abstractmethod
class Food(ABC):
_food_factory_map = {}
_recipes = {}
@classmethod
def getFood(cls, foodName):
return ...
2
votes
3
answers
2k
views
Is extension of an abstract parent class with an abstract child class bad design?
Is it bad design to have an abstract class inherit from another abstract class?
I have a single base node (class BaseNode) and 3 possible child node types (Sink, Process, and Source).
Is the ...
2
votes
2
answers
980
views
Questions about Polymorphism
So I understand the importance of Polymorphism, including how vital it is. But something I don't quite understand is what about the Constructor and any inherited Class the initial Base Class may have....
2
votes
1
answer
3k
views
Should I refactor my abstract classes into Helper classes? Real use of abstract classes and protected keyword?
A lot of my code seems to be going through the following evolution -
Iteration 1
interface IAccountManager {
void Import(string importData);
}
class SalesAccountManager : IAccountManager {
...
2
votes
5
answers
576
views
Polymorphism in nearly identical Classes
At the time I'm workin on a project with several Instances of an abstract class. Some functions in the subclasses are the same, some not. This would lead to code like the following. In the Code i use ...
2
votes
3
answers
375
views
Object Oriented Programming - what is the best way to add new parameters?
I have a doubt about what would be the right OOP approach for implementing classes that do similar stuff with different parameters.
To provide a simple example, I would use two polynomial classes, ...
2
votes
2
answers
6k
views
Sequence diagram for Abstract and Derived class
I've a bunch of classes where one is Abstract class. I draw few derived class from that Abstract base class. For example,
class IBase{
public:
*register(): bool*
*update(): bool*
};
class Derived:...
2
votes
1
answer
150
views
Using virtual inheritance for an interface system based on abstract classes
I want to use a physics engine (like bullet or PhysX) in my program, however I want to hide the actual physics engine from it, so I can easily swap it out with another during run-time (e.g. switch ...
2
votes
1
answer
99
views
Feedback on inheritance assignment
So I've got this java assignment for college and was just wondering if anyone here could give me some feedback as to what I've been thinking some of this means.
I've got a .csv file with building ...
2
votes
1
answer
3k
views
Creating multiple instances of an implementing class
I currently have an abstract class and multiple classes extending it. My problem is, that there has to be a way to create a variable number of instances of an extending class. The number of instances ...
1
vote
3
answers
4k
views
Why List<E> interface is additionally introduced in collection hierarchy? [duplicate]
Below is the diagram, where, if we just consider the implementations of List,
AbstractList maintains the core behavior of list. To introduce the new implementation class MyList(say) one can inherit ...
1
vote
3
answers
383
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
3
answers
42k
views
I want to understand clearly why can't we instantiate an object of an abstract class [duplicate]
Can I get a clear explanation why why can't we instantiate an object of an abstract class. I know abstract is not real. But I want to know more why can't we instantiate an object of an abstract class.
1
vote
1
answer
1k
views
Interface Dependencies or Abstract Classes
I have a decision to make and I am wondering what would be the better solution. I am refactoring an older application and intend to really get into the nuts and bolts of it.
There are 8 report types ...
1
vote
2
answers
1k
views
Is there a difference between abstract data type and interface?
From what I understand, an abstract data type is basically some data and what we are allowed to do with that data (ex. a list with a set of data and an attribute size and the functions get(), set(), ...
1
vote
3
answers
132
views
Method requires concrete implementation of collection. Should I change all upstream methods to return concrete implementations?
I have a method processDataAssumingLinkedHashMapInput() that processes a Map. The Map must be a LinkedHashMap ordered by values. Data comes from getStrIntMap(query). This method gets resultSet from ...
1
vote
3
answers
622
views
Refactoring a class to an abstract base class - keep default implementation in place or move it to an an other class?
I have a class which aggregates some temporal data from a database and provides a bunch of methods to query said data. It looks like this:
public class InfoProvider
{
public IEnumerable<...
1
vote
1
answer
1k
views
Names for generic classes - how to avoid naming them just "object"? Use synonyms?
When programming, I often end up naming some generic class (think of an abstract base class for stuff you manage in your project) something like FooObject, FooComponent or FooItem (where Foo is an ...
1
vote
5
answers
6k
views
When should i use an abstract class vs an interface? [duplicate]
I'm fairly new to programming. At school I am currently learning to program with Java. I want to build an application where i can store my collection of books, records, boardgames and such. Started ...
1
vote
3
answers
327
views
Should a property be in an abstract class if not directly used
I have an abstract base class that is inherited by several different other types. They were all using a type injected into their constructor. So I moved this property in to the abstract base class. ...
1
vote
1
answer
119
views
Proxy Pattern in Python
I'm reading a book on design patterns. On proxy pattern the code are following:
class SensitiveInfo:
def __init__(self):
self.users = ['nick', 'tom', 'ben', 'mike']
def read(self):
...
1
vote
1
answer
160
views
Abstract Base Class decides which type of child class to create at runtime
I have an Abstract Base Class AbstractModel
class AbstractModel {
public:
struct predictionStructure{};
virtual predictionStructure predict(CompanyLib::Matrix<double> data) = 0;
std::...
1
vote
3
answers
4k
views
Dependency Injection via Constructors vs Abstract Classes
For the past few days I've been researching the relationship of abstract classes and dependency-injected via the constructor classes.
It appears that any time that I can have a dependency-injected ...
1
vote
1
answer
5k
views
Abstract classes with static methods in PHP
Pre: I am looking at a quite big PHP project developed by a company which we need to partly interact with while building a new webapp.
The whole application is developed in PHP 5.
Most of the ...
1
vote
2
answers
1k
views
Convert this abstract class to an interface
I have a security method I would like to be able to sprinkle into other classes throughout my program. It is currently an abstract class but I feel it would be more appropriate as an interface. Can ...
1
vote
1
answer
107
views
Can this simple Bank example be considered as a valid Abstract Factory?
For teaching purposes, I'm trying to replicate in a more faithful way from this conceptual UML (from wikipedia):
In a "so-so" real world example, in my case, families of Loans and Insurances:
So, ...
1
vote
1
answer
87
views
Pseudo-Factory Abstract Class
So I have a requirement for something like this:
The client shouldn't be aware of how the actual classes are
implemented or constructed.
The classes implement a common interface
So I used Factory ...
1
vote
1
answer
208
views
Is it valid to create superclass instance in OOP?
I have couple of files in my folder, some of them can be checked for integrity. I have a xml file which describes which files can be checked for integrity and their checksum.
In OOP, let's assume I ...