Jump to content

Recommended Posts

Posted

I have been programming in Java for a while, but I can't clarify between Hiding and Overriding, which I thought they are basically meaning the same, ie, change the method implementation.

 

But in fact, no. However, the only difference I can clarify is the term "Hiding" is used for static method, and "Overriding" is used for instance method.

 

Is that it?? if not? can any one demonstrate an example that distinctly explain the difference between these two??

 

thanks

Posted

Well this is just my take on it, such as it's worth, but I would say that "overriding a method" is a subset of the concept of information hiding. Or to be more thorough, overriding is a subset of the concept of polymorphism which is a subset of information hiding.

 

From a functional perspective... I'm not sure that it makes any difference. These are concepts intended to help us to understand the various capabilities of object-oriented programming, and it doesn't really matter when it comes time to putting the nuts and bolts together.

 

But I guess what you're asking is whether there are examples of information hiding that are not examples of overriding a method, and the answer to that question is a very simple "yes". There are many examples of information hiding in a language, and overriding a method is just one of them.

 

One example may be seen any time you make a class "private" instead of "public". You've now hidden its contents from any client of that class, right? They can only access it through an interface. That's information hiding, but it's certainly not overriding.

 

Make sense?

Posted

In this case I have to agree with Pangloss. I've only ever used the term hiding used in relation to things like public/private/protected methods and variables. The other thing I've heard in this sort of area is implementing an abstract method.

Posted

thanks for the response.

 

But, to be more specific, I am saying method Hiding vs method Overriding.

 

not varriables.

 

First of all, do you know people why, when I "rewrite" the static method of the based class in its sub class, I "hide" instead of "override" the static method??

 

Please refer to Java language itself. thanks

Posted

As I understand it, you're only "overriding" if you actually change what the method will do in the subclass. If you're just interfacing with a higher class from a subclass, that's an implementation of the concept of information hiding, but it's not an example of "overriding".

 

This is exactly what I was talking about above, so you may want to read it carefully.

 

I think you may be confusing a functional term that refers to something you do with code (overriding) with a larger concept that's used in a more expository way (information hiding).

Posted

Well, why I got the rumor that the term hiding is used for static method, and overriding is used for instance method??

 

:)

 

any way, thanks

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.