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.

Filter by
Sorted by
Tagged with
2 votes
3 answers
235 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, ...
-1 votes
2 answers
87 views

Is an abstract role needed to ensure that a customer can only have one role out of several? [closed]

I have the following UML class diagram in a C++ context. I want to make sure that a Customer can have only one role: Can the Customer now only assume one role, and what does <<abstract>> ...
  • 11
1 vote
1 answer
81 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
3 answers
257 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<...
-2 votes
3 answers
143 views

Singleton as Interface for testability via dependancy injection

It can be found in many advices on topic that having Singletons is an anti-pattern. Especially for cases of testability. Can someone please advice/critique on this way (please see code below) of ...
  • 101
1 vote
1 answer
121 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::...
0 votes
1 answer
429 views

How to expose C++ static library interface, extending Pimpl to an abstract interface

Until today I had a static C++ library with no separation between the public interface and internal headers. My other apps just linked to it, included the required headers, and used whatever they ...
4 votes
4 answers
482 views

How name public method that relays to abstract methods of its children (c#)

I've run into the following situation multiple times, and in every case have struggled with the naming. I want a class to force its children to implement a method, but I want the parent class to be ...
  • 1,476
0 votes
3 answers
223 views

Java Inheritance Problem

I have the finance application where we can have different types of transactions, like balance enquiry, funds transfer, and pin change etc. Now the Transaction is a base class, and there are specific ...
1 vote
2 answers
425 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(), ...
  • 163
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) { ...
3 votes
1 answer
236 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 ...
  • 141
1 vote
1 answer
86 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, ...
  • 243
0 votes
1 answer
272 views

What is the difference between "Abstract Core" and "Pluggable Component Framework" concepts

I am reading Domain Driven Design by Eric Evans and there are 2 sub-chapters - Abstract Core & Pluggable Component Framework - that seems to me to refer to the same concept. I believe that there ...
  • 133
1 vote
5 answers
3k 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 ...
  • 21
23 votes
4 answers
5k views

Never make public members virtual/abstract - really?

Back in the 2000s a colleague of mine told me that it is an anti-pattern to make public methods virtual or abstract. For example, he considered a class like this not well designed: public abstract ...
5 votes
1 answer
842 views

How to go ahead with methods that only one derived class implements from a common interface?

I have one interface (let's say in C++) that has been implemented by some derived classes. Let's suppose that the interface is like this: class IBase { virtual bool method_1() = 0; virtual long ...
2 votes
1 answer
101 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 ...
3 votes
1 answer
3k 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 ...
  • 141
3 votes
1 answer
8k 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 ...
  • 187
4 votes
2 answers
104 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 ...
's user avatar
17 votes
4 answers
3k views

When to move a common field into a base class?

I currently have two derived classes, A and B, that both have a field in common and I'm trying to determine if it should go up into the base class. It is never referenced from the base class, and say ...
  • 455
1 vote
1 answer
78 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 ...
  • 199
3 votes
5 answers
1k views

How to avoid the continuous downcasting in this case?

I have an abstract class Dog and multiple subclasses (Beagle, Labrador, Bulldog...) extendig it. I have a DogHouse that can store a Dog. My problem is that when I put for example a Beagle into a ...
  • 149
0 votes
3 answers
3k 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
3 answers
93 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. ...
  • 121
13 votes
5 answers
5k views

Does it make sense to define an interface if I already have an abstract class?

I have a class with some default/shared functionality. I use abstract class for it: public interface ITypeNameMapper { string Map(TypeDefinition typeDefinition); } public abstract class ...
  • 1,441
30 votes
2 answers
5k views

Implementation of pure abstract classes and interfaces

Although this isn't mandatory in the C++ standard, it seems the way GCC for example, implements parent classes, including pure abstract ones, is by including a pointer to the v-table for that abstract ...
  • 1,043
2 votes
1 answer
94 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 ...
21 votes
4 answers
4k views

Use abstract class in C# as definition

As a C++ developer I'm quite used to C++ header files, and find it beneficial to have some kind of forced "documentation" inside the code. I usually have a bad time when I have to read some C# code ...
0 votes
3 answers
361 views

Send records using async or sync way

I have bunch of keys and values that I want to send to our messaging queue by packing them in one byte array. I will make one byte array of all the keys and values which should always be less than 50K ...
2 votes
2 answers
781 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 { /// <...
  • 129
0 votes
1 answer
517 views

How to design inheritance from abstract class which is not initiated but seemingly must be initiated?

I need to design a program in Java which calculates arithmetic expressions (only addition or subtraction). Requirements: 1) abstract class Expression which contains abstract method calculate(...
  • 145
3 votes
1 answer
427 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 ...
  • 145
2 votes
2 answers
5k 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:...
  • 39
11 votes
6 answers
4k views

What code should be included in an abstract class?

I am troubled lately about the use of abstract classes. Sometimes an abstract class is created in advance and work as a template of how the derived classes would work. That means, more or less, that ...
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 ...
  • 1,047
9 votes
3 answers
4k views

Properly designing an abstract class: How to retrieve data?

I come from a self taught background and am trying to shore up my weaknesses in OOP, specifically C# and class design. I've been reading Code Complete 2 and it became apparent that I'm not following ...
  • 101
5 votes
1 answer
370 views

When can client code know about strategy pattern implementations?

I am considering using a strategy pattern for configuration file management, that way I can support some legacy configs. I feel pretty solid on the overall design (as its pretty standard strategy ...
  • 133
1 vote
2 answers
465 views

Options for derived classes of two abstract base classes

Let's say there are classes D1, D2, etc. describing different types of an abstract class D. Let's say there are SenderReceiver classes describing different ways of communicating for each D1, D2, etc.:...
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 ...
  • 31
7 votes
9 answers
2k views

Another "Why use Abstract/Interface" question. But I'm a solo developer. Why use it?

I know the purpose of it and everything. I see myself as a solo developer for a couple more years. I always see answers that it is contract. Yes I get it. But here's something on my mind: If a ...
  • 189
4 votes
2 answers
1k views

OOP: Switching on polymorphic types and maintaining state throughout workflow

High level: I think my design pattern is flawed. Despite implementing Polymorphism, I find myself relying on large switch statements based on derived Type within my WPF application. As I'm adding more ...
3 votes
2 answers
5k views

Where should I use abstract classes vs interfaces for a REST API client?

I'm trying to write a REST API client for practice and I'm having trouble figuring out how lay out the project. The approach I'm taking right now has Actions, DomainObjects, Requests, and a class ...
  • 274
-2 votes
3 answers
1k views

Can I say Interface is a set of general behavior? [duplicate]

I'm new to OOP. Can I say Interface is a set of general behavior that may be have and act uniquely by a set of objects that have in common? And Abstract class has similarity with Interface but it have ...
  • 1
0 votes
3 answers
6k views

Strategy Pattern with abstract class instead of interface?

Is the strategy in the strategy pattern always an interface? What pattern would it be when the strategy is abstract?
1 vote
1 answer
207 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 ...
1 vote
1 answer
2k 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 { ...
  • 415
1 vote
3 answers
131 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 ...
  • 103
3 votes
2 answers
821 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)...
  • 201