2013-06-14 5 views
0

콘크리트의 하위 클래스 (추상 클래스가 아님)가 추상 클래스인지 아닌지 알고 싶습니다. 가상의 예에서 : 나는 ComputationalNode의 인스턴스 또는 ComputationalNode 같은 유형을 바인딩 템플릿을 사용하여 forbide하려면 위의 예에서.NET에서 비 추상화를 상속 한 추상 클래스?

public class HistoricallyManaged<SpecificType> 
    { // code to manage history } 

public abstract class ComputationalNode<SpecificType>: HistoricallyManaged<SpecificType> 
    { // common methods implemented, but some left to concrete classes } 

public class Formula<SpecificType>: ComputationalNode<SpecificType> 
    { // code to manage common formula behavior like checking if parameters have been calculated } 

public class Variable<SpecificType>: ComputationalNode<SpecificType> 
{ // code to manage common variable behavior like persisting values } 

// usage example 
public class SomeOtherClass { 
    private Formula<int> intFormula; 
    private Formula<double> doubleFormula; 
    private Variable<int> intVar; 
    private Variable<double> doubleVar; 
} 

그러나 나는 및 다른 유형의 HistoricallyManaged 선언 허용 하시겠습니까, 계층 구조 인스턴스화가 더 높아야하지만 중간 수준에서는 가능하지 않아야합니다.

귀하의 소중한 도움에 감사드립니다.

+0

당신이 그것을 시도 했습니까? 어떻게 된 거예요? –

+0

그래서, 컴파일합니까? 실행됩니까? 확실히 그 대답을 줄까요? – Oded

답변

0

물론 가능합니다. object 그렇게 모든abstract class 실제로이의 예입니다 (IMO 비록 그것이 있어야) abstract되지 않습니다 :

abstract class Foo {} // tada! - note this is implicitly : object 

당신이 그것의 인스턴스를 생성하기 전에 당신은 더 비 abstract로 서브 클래 싱해야 그래도.

그러나 명시하기 :

class Foo {} // fine 
abstract class Bar : Foo {} // fine 
class Blap : Bar {} // fine 
관련 문제