abstract-class

Abstract classes and PyMongo; can't instantiate abstract class

☆樱花仙子☆ 提交于 2019-12-18 09:44:55
问题 I created the empty abstract class AbstractStorage and inherited the Storage class from it: import abc import pymongo as mongo host = mongo.MongoClient() print(host.alive()) # True class AbstractStorage(metaclass=abc.ABCMeta): pass class Storage(AbstractStorage): dbh = host def __init__(self): print('__init__') Storage() I expected the output to be True __init__ however, the one I'm getting is True Traceback (most recent call last): File "/home/vaultah/run.py", line 16, in <module> Storage()

Bodyless constructor in non-abstract C# class

自闭症网瘾萝莉.ら 提交于 2019-12-18 09:02:24
问题 I'm trying to understand the following class provided in the MVC framework; it seems like the class should be abstract, but it is not, and yet this class compiles. Is the class actually abstract despite the missing "abstract" keyword? What am I missing here? namespace Microsoft.AspNet.Identity.EntityFramework { public class IdentityUser : IUser { public IdentityUser(); public IdentityUser(string userName); public virtual ICollection<IdentityUserClaim> Claims { get; } public virtual string Id

C++ : How can I know the size of Base class SubObject?

浪子不回头ぞ 提交于 2019-12-18 07:06:49
问题 . Here I was discussing Empty Base Optimization, and MSalters made this interesting comment: No class can ever have sizeof(Class)==0, empty or not. But we're talking specifically over the size of an empty base class subobject. It doesn't need its own vtable, nor a vtable pointer. Assume the common layout of a vtable pointer at offset 0; that would cause the zero-sized base class subobject to share its vtable pointer with the derived class. No problem: those should be identical anyway, that's

How to disable parameterless constructor in C#

随声附和 提交于 2019-12-18 04:33:56
问题 abstract class CAbstract { private string mParam1; public CAbstract(string param1) { mParam1 = param1; } } class CBase : CAbstract { } For the class CBase, it should be initialized by providing the parameter, so how to disable the parameterless constructor for CBase class? 回答1: If you define a parameterized constructor in CBase , there is no default constructor . You do not need to do anything special. If your intention is for all derived classes of CAbstract to implement a parameterized

Abstract Class:-Real Time Example

十年热恋 提交于 2019-12-18 01:42:13
问题 Recently in a interview I was asked a very general question "what is abstract in java".I gave the definition and it was followed with some other question on abstract as what is abstract method and difference between abstract method and concrete method and etc. Then at last interviewer asked to give a real time example when I should use or define a class as abstract.I got confused.I gave some example but he was not convinced. I googled it but found no real solution. So can someone give me real

Why do we need abstract classes in C++?

我的梦境 提交于 2019-12-17 23:18:24
问题 I've just learned about polymorphism in my OOP Class and I'm having a hard time understanding how abstract base classes are useful. What is the purpose of an abstract class? What does defining an abstract base class provide that isn't provided by creating each necessary function in each actual class? 回答1: The purpose of an abstract class is to define a common protocol for a set of concrete subclasses. This is useful when defining objects that share code, abstract ideas, etc. Abstract classes

How to create an object of an abstract class and interface

霸气de小男生 提交于 2019-12-17 18:35:51
问题 How do I create an object of an abstract class and interface? I know we can't instantiate an object of an abstract class directly. 回答1: You can not instantiate an abstract class or an interface - you can instantiate one of their subclasses/implementers. Examples of such a thing are typical in the use of Java Collections. List<String> stringList = new ArrayList<String>(); You are using the interface type List<T> as the type, but the instance itself is an ArrayList<T> . 回答2: To create object of

LINQ to SQL - mapping exception when using abstract base classes

走远了吗. 提交于 2019-12-17 17:41:56
问题 Problem: I would like to share code between multiple assemblies. This shared code will need to work with LINQ to SQL-mapped classes. I've encountered the same issue found here, but I've also found a work-around that I find troubling (I'm not going so far as to say "bug"). All the following code can be downloaded in this solution. Given this table: create table Users ( Id int identity(1,1) not null constraint PK_Users primary key , Name nvarchar(40) not null , Email nvarchar(100) not null )

Testing Abstract Classes

╄→尐↘猪︶ㄣ 提交于 2019-12-17 17:33:09
问题 How do I test the concrete methods of an abstract class with PHPUnit? I'd expect that I'd have to create some sort of object as part of the test. Though, I've no idea the best practice for this or if PHPUnit allows for this. 回答1: Unit testing of abstract classes doesn't necessary mean testing the interface, as abstract classes can have concrete methods, and this concrete methods can be tested. It is not so uncommon, when writing some library code, to have certain base class that you expect to

Performance difference between passing interface and class reloaded

本小妞迷上赌 提交于 2019-12-17 16:30:11
问题 There's a consensus that using interfaces is better than using classes. I surely agree: a library method accepting ArrayList instead of List would be a crap. There's also a consensus that the performance is always the same. Here my benchmark begs to differ. There are 1 to 4 implementations of both an interface and an abstract class. When more than two implementations get used, the performance starts to diverge. I'm looking for an explanation for this behavior (and also for the origin of the