Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...Keep up the good work - excellent site - i'd been looking for something like this for ages !..."

Geography

Where in the world do Tek-Tips members come from?

disabling method from an extended class?Helpful Member! 

fenris (Programmer)
17 Aug 00 15:38
I have a parent class with a number of methods.

For all the child classes except one, they all use the methods in addition to some of their own. I have one class that doesn't require one of the methods of the parent class and it doesn't make sense for that particular child to have access to that method. Is there anyway that I can "block" the child from accessing that method of the parent class.

To clarify this, I make an abstract class called 3dShapes. It has abstract methods of getLength(), getWidth() and getHeight(). Now these methods make sense when you are deal with cubes and such, but the width or height method doesn't make sense when it comes to a sphere.

I hope this is clear.....

Troy Williams B.Eng.
fenris@hotmail.com

Helpful Member!  rbobbitt (Programmer)
17 Aug 00 23:55
Your dilemna is probably an indication of a basic design flaw. In the example you give, the 3DShapes class shouldn't have a getWidth() or getHeight() method because, like you said, this doesn't make sense for all 3D shapes (um, not sure how you would figure the length of a sphere either). Having these methods in a class like this is like having a deploySunroof() method in a base car class (not ALL cars have sunroofs!).

Without knowing the specifics of your problem, it sounds like you need to remove some attributes/methods from your base class, add a couple of intermediate classes that both extend the base class and then have all but one of your original subclasses extend one of the new classes and the remaining subclass extend the other new class. Similar to below where 3DShape is your base class and Rectangle, Square and Sphere were the classes that originally extended it. (the diagram is a bit messy in here)

                     3DShape
                        ¦
          --------------------------------
          ¦                              ¦
    CircularShape                   BoxLikeShape
          ¦                              ¦
    -------                         ------------
    ¦                              ¦            ¦
 Sphere                          Square     Rectangle
fenris (Programmer)
18 Aug 00 8:24
Thank you very much for your answer, it was very informative and the type of answer that I was looking for. This is the kind of stuff that I know I am lacking. I wasn't sure how to approach this problem. I come from a very strong procedural background and am into speed, getting the code to run as fast as possible, not the illegal stuff ;) . I had no trouble learning the syntax and how to create A class that can do something like numerical root finding. But when it comes to things like creating object hierarchies that make sense is where I have toruble.

How does having intermediate classes affect the performance of the java application in general?

Troy Williams B.Eng.
fenris@hotmail.com

phimlob (Programmer)
22 Aug 00 15:57
Hi :)
In answer to your last question, from experience I'd say not much at all. Some of my classes are subclassed maybe 7 8 times or so and theres no remarkable difference in effectivity of the system. (these classes all subclass some java class, which in turn often is several steps away from the Object class.)

On the other hand, it lets me organize my thinking into groups and sub-groups, making it really easy to code and reuse code in totally different programs. Also, its easier for other programmers to work on separate parts of the program (classes) without real problems (this, of course, is in small systems... my client server system with 150+ classes is a pain... but you get my point.)

So I guess once you learn to plan your classes and their relations in an object-oriented way you save time in various parts of the coding phase but not that much in actual performance.

Finally, if you want speed, try to analyze where in the code it gets bogged down, then write that part in c. Java lets you use compiled C code methods... I've done this rarely, but it does make things faster.

Hope this helps explain things.
Cheers
Mattias
fenris (Programmer)
23 Aug 00 8:00
Thanks for your response, I appreciate it. I know how to code but not in an OO way. That is for me the hardest part but I am starting to get the hang of it.

Troy Williams B.Eng.
fenris@hotmail.com

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close