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

  • sghaff1

    sghaff1

    23 Mart 2009
  • Sorikan

    Sorikan

    3 ŞUBAT 2008
  • YAN TV

    YAN TV

    20 EKİM 2011