English 中文(简体)
Racket子类具有约束力的自动继承
原标题:Automatic inheritance of bindings in Racket subclasses

Im有几类子级的班级,所有使用方法和田地都来自母级。 是否有“正确”的处理方式?

到目前为止,我一直在使用<代码>(依旧方法1方法2......)。

我徒劳地寻求一种方式,即母阶级可以迫使子阶级继承约束性。 我理解,这种方式可能是坏的。

Racket或OOP没有经验。

最佳回答

The methods are inherited even if you don t use inherit. To call a method from a super class, one can use (send this method arg1 ...). The form (inherit method) inside a class form will make the method available in form (method arg1 ...) inside the body. This is not just a convenient shorthand, but is also more efficient than (send this method).

我不知道一揽子继承形式,但你可以用很少的宏观方式自行推出。 例如:

(define-syntax (inherit-from-car stx) 
  (datum->syntax stx  (inherit wash buy sell)))

(define car% (class object%
               (define/public (wash) (display "Washing
"))
               (define/public (buy)  (display "Buying
"))
               (define/public (sell) (display "Selling
"))
               (super-new)))

(define audi% (class car% (super-new)
                (inherit-from-car)
                (define/public (wash-and-sell)
                  (wash)
                  (sell))))

(define a-car (new audi%))
(send a-car wash-and-sell)
问题回答

暂无回答




相关问题
Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

JSON with classes?

Is there a standardized way to store classes in JSON, and then converting them back into classes again from a string? For example, I might have an array of objects of type Questions. I d like to ...

Object-Oriented Perl constructor syntax and named parameters

I m a little confused about what is going on in Perl constructors. I found these two examples perldoc perlbot. package Foo; #In Perl, the constructor is just a subroutine called new. sub new { #I ...

Passing another class amongst instances

I was wondering what is the best practice re. passing (another class) amongst two instances of the same class (lets call this Primary ). So, essentially in the constructor for the first, i can ...

Where can I find object-oriented Perl tutorials? [closed]

A Google search yields a number of results - but which ones are the best? The Perl site appears to contain two - perlboot and perltoot. I m reading these now, but what else is out there? Note: I ve ...

热门标签