Questions tagged [abstract-class]

Abstract classes are classes which cannot be instantiated. They exist to provide common functionality and interface specifications to several concrete classes.

Abstract classes are classes which cannot be instantiated. They exist to provide common functionality and interface specifications to several concrete classes.

From Abstract Type on Wikipedia:

Abstract classes can be created, signified, or simulated in several ways:

  • By use of the explicit keyword abstract in the class definition, as in Java, D or C#.
  • By including, in the class definition, one or more methods (called pure virtual functions in C++), which the class is declared to accept as part of its protocol, but for which no implementation is provided.
  • By inheriting from an abstract type, and not overriding all missing features necessary to complete the class definition.
  • In many dynamically typed languages such as Smalltalk, any class which sends a particular method to this, but doesn't implement that method, can be considered abstract. (However, in many such languages, the error is not detected until the class is used, and the message returns results in an exception error message such as "does Not Understand").
5262 questions
2
votes
3 answers

C++ Abstract Classes and Inheritance

I have this problem I'm trying to solve. Basically the base class has the function map, which takes a vector as input and outputs the final vector after some mapping function, in this case - f, has been performed. However, I'm really lost as to why…
Athena
  • 320
  • 2
  • 12
2
votes
1 answer

PowerMockito mock abstract and non-public parent method that child class doesn't have

Hi I have a code like this: ``` abstract class AbstractBaseClass { public String method() { return "AbstractBaseClass.method"; } } public class ChildClass extends AbstractBaseClass { public String start() { } } @Test public void test()…
hongchangfirst
  • 245
  • 3
  • 17
2
votes
0 answers

Using abstract base classes to specify an interface enforcing input and return types

I want to write an abstract base class that should enforce that its derived classes implement one method with specific parameters and specific returns. However, since in Python you specify neither the return type nor the argument types in the…
Alex
  • 3,316
  • 4
  • 26
  • 52
2
votes
2 answers

Error using the generic type BaseUser requires 1 argument

I have an interface public interface IIdentity { T GetUser(); } I have a base class that implements the Interface as an abstract method public abstract class BaseUser : IIdentity { public string UserId { get; set; } public…
fuzzybear
  • 2,325
  • 3
  • 23
  • 45
2
votes
1 answer

Java specify subclass constructor signature

I want to create a method that constructs an object of a class received as a parameter much like the following one: public static T makeObject(Class c){ ObjectReceivedFromService orfs = getObjectFromService(); …
Emroy
  • 85
  • 10
2
votes
0 answers

Angular: Injectable() decorator with abstract class

I encountered strange situation and want to discuss is it correct or not. (please also look for little question update at the end) In angular 4.3 I have some abstract class which is extended by few angular components. It looks like: export abstract…
Max Minin
  • 453
  • 1
  • 4
  • 8
2
votes
1 answer

How to impose to set a property in class definition

I want to create an abstract class such that subclasses will raise an error when instanced if they don't implement an abstract property. An error should be also raised if the attribute is a method rather than a property. My attempt: from abc import…
MLguy
  • 1,776
  • 3
  • 15
  • 28
2
votes
0 answers

Python 3 threadings.Thread callback error when targeting abstract method

base_class.py import threading import websocket from abc import ABCMeta, abstractmethod class A: __metaclass__ = ABCMeta def __init__(self): self.some_var = 0 @abstractmethod def failed_method(self): pass …
2
votes
1 answer

Abstract Classes in OOP PHP

I am having very strange behavior in my abstract class. here is my code :
Rakesh K
  • 1,290
  • 1
  • 16
  • 43
2
votes
2 answers

Cannot convert return expression of type 'NodeType.NodeType?' to return type 'NodeType?'

I have been dealing with this problem in Swift for a while, tried type erasure and all kinds of stuff, but to no avail; and the problem seems to be common sense (at least to me). How can I emulate abstract class in Swift? In other words, how to make…
user9385286
2
votes
2 answers

Best design for Java Parsing several CSV files with different headers and model objects

I have several CSV files that I will need to Parse. and use later for Insert in MYSQL. I have already written one parser but I want to avoid as much as I can code duplication I have already in mind that I should use an abstract class, or maybe a…
ErEcTuS
  • 777
  • 1
  • 14
  • 33
2
votes
2 answers

Can "override abstract methods" be substituted with "implement abstract methods" in Java inheritance?

In Java inheritance, can the expression "overriding an abstract method" be used interchangeably with the expression "implementing an abstract method"? I came across the following question in the book "OCA Java SE 8 Programmer I Study Guide" in…
2
votes
1 answer

Call through the base class abstract method

I have an interface from which a user derives multiple classes which I have no knowledge of but still I want to call these derived classes common method Run(). The Event class is intended to be an interface so I know how to call my unknown…
Pedro
  • 74
  • 1
  • 11
2
votes
3 answers

Understanding Generics combined with inherited classes

This is a question related to another one I asked that was specific to NHibernate, but I'm starting to think that my question might be far more fundamental than that. ForNHibernate-related reasons, I have a base abstract class (Listing) and…
Alastair
  • 5,894
  • 7
  • 34
  • 61
2
votes
2 answers

Abstract factory pattern

I have a class, CMyDataClass, to store data, which has three member variables and two constructors like public class CMyDataClass { public String strIndex, strName; public int nType; public CMyDataClass() { strIndex = ""; …
Thorin Oakenshield
  • 14,232
  • 33
  • 106
  • 146
1 2 3
99
100