SORU
10 Ocak 2010, Pazar


Özellikleri ve soyut yöntemler Scala geçersiz kılar

Baz soyut bir sınıf (özellik) var. 2* *soyut bir yöntemi vardır. Genişletilmiş ve çeşitli türetilmiş sınıflar tarafından yürütülmektedir. foo() uygular ve sonra türetilmiş sınıf foo() aramaları, böylece türetilmiş sınıfları içine karışabilir bir özellik oluşturmak istiyorum.

Gibi bir şey

trait Foo {
  def foo()
}

trait M extends Foo {
  override def foo() {
    println("M")
    super.foo()
  }
}

class FooImpl1 extends Foo {
  override def foo() {
    println("Impl")
  }
}

class FooImpl2 extends FooImpl1 with M 

Kendi türleri ve yapısal türleri çalıştım, ama işe giremiyorum.

CEVAP
10 Ocak 2010, Pazar


Çok yakındın. M. foo soyut değiştirici ekleyin ve 'Özellik' deseni: 7**. mükemmel bir Yazıcı var

trait Foo {
  def foo()
}

trait M extends Foo {
  abstract override def foo() {println("M"); super.foo()}
}

class FooImpl1 extends Foo {
  override def foo() {println("Impl")}
}

class FooImpl2 extends FooImpl1 with M

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Michael Lummio

    Michael Lumm

    25 Mayıs 2007
  • bored before i even began

    bored before

    30 Mart 2009
  • TV and Lust

    TV and Lust

    26 HAZİRAN 2006