Book a Demo

Author Topic: Method Overrides (Code Generation)  (Read 2794 times)

eauser_4418

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Method Overrides (Code Generation)
« on: October 31, 2006, 06:18:26 pm »
Hello,

I am trying to generate code where ClassB is a subclass of ClassA.

ClassA has methods that I do not want to override in ClassB.

However, when I generate ClassB (in a different package from ClassA and I'm not generating ClassA nor do i wish to), all of ClassA's methods appear in ClassB (i.e. they all get overridden).

How do I prevent this?

Thanks,

Matthew

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Method Overrides (Code Generation)
« Reply #1 on: October 31, 2006, 07:10:02 pm »
You haven't provided a whole lot of information to go on, but as a guess the methods in the parent class are abstract and the option to automatically generate methods is checked.  (Tools | Options | Attribute/Operations | Generate methods for implemented interfaces)

eauser_4418

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Method Overrides (Code Generation)
« Reply #2 on: October 31, 2006, 07:25:48 pm »
Hello,

I think the problem as follows (being more detailed with the object model now)...

In the afore mentioned post, ClassA implements InterfaceA and implements the methods of that interface (of which there is one).

ClassB implements InterfaceB which extends from InterfaceA but is also a sub-class of ClassA.

InterfaceA has methods that are implemented by ClassA that in turn is a super-class to ClassB.

Now, lets say InterfaceA has one method that is implemented by ClassA. InterfaceB has no methods.

However, since ClassB implements IntefaceB (which extends InterfaceA), if ClassB was not a sub-class of ClassA, it would have to implement the methods of InterfaceA.

But ClassB is a sub-class of ClassA which already implememts the methods of InterfaceA.

The question is, if the source generator first looks at the interfaces being implemented by ClassB (since InterfaceB has no methods, then just those of InterfaceA would have to be implemented), does it ignore the fact that the method is already implemented in ClassA?

To summarize, with source generation, are the interfaces considered first (and the methods generated accordingly) before the super-class methods are even taken into account thereby negating the need to generate methods in the subclass (i.e. ClassB)?

Thanks,

Matthew

eauser_4418

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Method Overrides (Code Generation)
« Reply #3 on: October 31, 2006, 09:42:34 pm »
The suggestion regarding the Tools -> Options -> Attribute / Operations works (but am still wondering about the last scenario I presented). Thanks for that.

I notice that each time I select a package in the project browser and then (from the right mouse click menu), choose Code Engineering -> Synchronize Package With Code -> Forward Engineer (with children), every time the Java source file is updated extra newlines end up at the end of the source file.

Thanks,

Matthew