tags:

views:

213

answers:

1

New to scala and can't seem to find a reference on this situation.

I'm trying to override some methods on scala.swing.TabbedPane.pages: The definition of this class is:

class TabbedPane extends Component with Publisher {
   object pages extends BufferWrapper[Page] {
     def += 
   }
}

I can't figure out the syntax for overriding any method in the internal pages object. Is this possible with scala?

Thanks.

EDIT: To make this question clearer.

class CloseableTabbedPane extends TabbedPane{

}

val pane = new CloseableTabbedPane;
pane.pages += new CloseablePage;

I need to override the method pane.pages += to accept a CloseablePage with an icon.

+1  A: 

In the normal case of overriding a method in a class:

scala> class Foo { def foo : String = "Foo" }
defined class Foo

scala> class Bar extends Foo { override def foo : String = "Bar" }
defined class Bar

scala> val b = new Bar
b: Bar = Bar@1d2bb9f

scala> b.foo
res0: String = Bar

However, you've asked as to whether it is possible to override an object:

scala> class FooBar {
 | object prop extends Foo {
 |   def foo2 : String = "foo2"
 | }
 | }
defined class FooBar

scala> val fb = new FooBar
fb: FooBar = FooBar@183d59c

scala> fb.prop.foo
res1: String = Foo

Now for the override:

scala> fb.prop.foo2
res2: String = foo2

scala> class FooBaz extends FooBar {
 | override object prop extends Bar {
 | def foo2 : String = "bar2"
 | }
 | }
<console>:8: error: overriding object prop in class FooBar of type object FooBaz.this.prop;
 object prop cannot be used here - classes and objects cannot be overridden
   override object prop extends Bar {
                   ^

It doesn't really make sense, as how could you ensure that the overridden value also extended Foo?

oxbow_lakes
overriding a normal class method isn't what the question is, sorry if I didn't make it clearer. It's overriding a method that exists inside the object "pages" that exists inside the class TabbedPane.
justin
Changed answer now
oxbow_lakes
Well I'd agree that it doesn't make sense, but I'm wondering why would anyone make an API like this since it's so difficult to override functionality. Perhaps there is an easier way to do what I'm trying to accomplish?
justin