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
-1 votes
2 answers
86 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>> ...
user avatar
  • 11
0 votes
1 answer
72 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): ...
user avatar
1 vote
3 answers
205 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<...
user avatar
-2 votes
3 answers
96 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 ...
user avatar
  • 1
0 votes
1 answer
117 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::...
user avatar
0 votes
1 answer
312 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 ...
user avatar
4 votes
4 answers
359 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 ...
user avatar
  • 1,477
0 votes
3 answers
218 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 ...
user avatar
1 vote
2 answers
327 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(), ...
user avatar
  • 163
8 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) { ...
user avatar
2 votes
1 answer
197 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 ...
user avatar
  • 131
1 vote
1 answer
84 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, ...
user avatar
  • 243
0 votes
1 answer
238 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 ...
user avatar
  • 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 ...
user avatar
  • 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 ...
user avatar
5 votes
1 answer
808 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 ...
user avatar
  • 179
1 vote
1 answer
95 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 ...
user avatar
2 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 ...
user avatar
  • 131
3 votes
1 answer
7k 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 ...
user avatar
  • 187
3 votes
2 answers
103 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
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 ...
user avatar
  • 455
0 votes
1 answer
76 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 ...
user avatar
  • 189
3 votes
5 answers
986 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 ...
user avatar
  • 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 ...
user avatar
1 vote
3 answers
83 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. ...
user avatar
  • 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 ...
user avatar
  • 1,401
29 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 ...
user avatar
  • 1,023
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 ...
user avatar
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 ...
user avatar
0 votes
3 answers
360 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 ...
user avatar
2 votes
2 answers
738 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 { /// <...
user avatar
  • 129
0 votes
1 answer
514 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(...
user avatar
  • 145
3 votes
1 answer
418 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 ...
user avatar
  • 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:...
user avatar
  • 39
10 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 ...
user avatar
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 ...
user avatar
  • 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 ...
user avatar
  • 101
5 votes
1 answer
363 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 ...
user avatar
  • 133
1 vote
2 answers
451 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.:...
user avatar
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 ...
user avatar
  • 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 ...
user avatar
  • 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 ...
user avatar
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 ...
user avatar
  • 264
-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 ...
user avatar
  • 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?
user avatar
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 ...
user avatar
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 { ...
user avatar
  • 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 ...
user avatar
  • 103
3 votes
2 answers
791 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)...
user avatar
  • 201
7 votes
3 answers
24k views

C++ derived class copy constructor

If I have an abstract class Drink which has a derived class Coffee, what would the copy constructor for Coffee look like? If it accepts a reference of Type Coffee as a parameter then I wouldn't be ...
user avatar
  • 73