1 2 3 Previous Next 33 Replies Latest reply: May 23, 2013 4:52 PM by user1983440 RSS

    Method hiding PL/SQL

    1009786
      Hi Experts,

      Could you please explain the concept of method hiding in Oracle PL/SQL with an example? When to use method hiding?

      Thanks & Regards,
      John

      Edited by: 1006783 on May 19, 2013 4:58 PM
        • 1. Re: Method hiding PL/SQL
          sb92075
          1006783 wrote:
          Hi Experts,

          Could you please explain the concept of method hiding in Oracle PL/SQL with an example? When to use method hiding?
          when all else fails, Read The Fine Manual

          http://docs.oracle.com/cd/E11882_01/appdev.112/e25519/wrap.htm#LNPLS016


          How do I ask a question on the forums?
          SQL and PL/SQL FAQ
          • 2. Re: Method hiding PL/SQL
            rp0428
            Welcome to the forum!

            Whenever you post provide your 4 digit Oracle version.
            >
            Could you please explain the concept of method hiding in Oracle PL/SQL with an example?
            >
            First, you need to explain what you mean by 'method hiding'.
            • 3. Re: Method hiding PL/SQL
              1009786
              Hi ,

              This is the explanation from the oracle documentation
              "
              Redefining an inherited method to customize its behavior in a subtype is called overriding, in the case of member methods, or *hiding*, in the case of static methods."

              link
              http://docs.oracle.com/cd/B28359_01/appdev.111/b28371/adobjbas.htm#i471260

              I am novice programmer trying to understand the concept in detail.
              • 4. Re: Method hiding PL/SQL
                rp0428
                >
                This is the explanation from the oracle documentation
                "
                Redefining an inherited method to customize its behavior in a subtype is called overriding, in the case of member methods, or hiding, in the case of static methods."

                link
                http://docs.oracle.com/cd/B28359_01/appdev.111/b28371/adobjbas.htm#i471260

                I am novice programmer trying to understand the concept in detail.
                >
                First - that functionality only applies to code WITHIN custom object types. And MOST Oracle PL/SQL code you will ever run into, novice or expert, will make little or no use of the methods withing the objects.

                As a novice programmer your time would be better spent learning SQL first and then PL/SQL afterward.

                Nevertheless as the doc states:
                >
                Static methods are invoked on the object type, not its instances. You use a static method for operations that are global to the type and do not need to reference the data of a particular object instance.
                >
                So when you redefine a 'static' method in a subtype you are 'hiding' the base class static method. The static method that is called depends solely on the object type that is used in the call. You cannot call the parent static method when calling the method on the child type; the parent method is 'hidden'. The parent method can only be called by calling the method on the parent object type.

                The main reason for this is the static binding that is done for overridden static methods. The actual static method to call is determined at compile time. For non-static methods that determination is made at execution time.

                That same doc explains the difference between 'overriding' and 'hiding'
                >
                Overriding and hiding are similar in that, in either case, the version of the method redefined in the subtype eclipses the original version of the same name and signature so that the new version is executed rather than the original one whenever a subtype instance invokes the method. If the subtype itself has subtypes, these inherit the redefined method instead of the original version.

                With overriding, the system relies on type information contained in the member method's implicit self argument to dynamically choose the correct version of the method to execute. With hiding, the correct version is identified at compile time, and dynamic dispatch is not necessary.
                >
                That difference allows you to call an 'overridden' method from a base class.

                See this section of the doc if you really want details.
                >
                Generalized Invocation
                Generalized invocation provides a mechanism to invoke a method of a supertype or a parent type, rather than the specific subtype member method. Example 2-15 demonstrates this using the following syntax:
                >
                The best advice would be what I told you up front - don't use the object-relational features of Oracle unless you are absolutely sure you can't get the same job done using the standard database features.

                Even if you become an expert in those object-relational features there would be little demand for your skills.
                • 5. Re: Method hiding PL/SQL
                  1009786
                  hi, Thanks for your time. Could you please give an simple example?
                  • 6. Re: Method hiding PL/SQL
                    rp0428
                    >
                    hi, Thanks for your time. Could you please give an simple example?
                    >
                    An example of what? That doc already has examples and code that demonstrate all of what I just discussed.

                    Skills in Oracle's object-relational features are not in demand. You would be hard pressed to find a shop that uses the features you are asking about.

                    If you are a novice seeking to gain expertise in useful and marketable skills you should learn SQL first, and then PL/SQL. Learning to create and use objects, except for the trivial one level objects and collections, would be far, far down the list.
                    • 7. Re: Method hiding PL/SQL
                      1009786
                      Hi, thanks a lot for your example. The documentation example is somewhat vague to understand. If you are not sure, please leave the option to Experts on this forum.
                      • 8. Re: Method hiding PL/SQL
                        sb92075
                        When you start with the wrong question, no matter how good an answer you get, it won't matter very much.
                        • 9. Re: Method hiding PL/SQL
                          rp0428
                          >
                          The documentation example is somewhat vague to understand.
                          >
                          I don't have any problem understanding it. Anyone that is already familiar with Object-oriented principles from another language such as Java or C++ shouldn't have any trouble understanding Oracle's more limited implementation of that similar functionality.

                          If you are NOT familiar with object-oriented principles already then Oracle's implementation is definitely NOT the place to start.
                          >
                          If you are not sure, please leave the option to Experts on this forum
                          >
                          There is no 'option' that needs to be left to anyone. Any volunteer can choose to reply if they wish.

                          The only thing I am not sure of is exactly what it is you are trying to understand and why you are even wanting to understand an implementation that is seldom used and of little practical application in any Oracle environment you are likely to become associated with.

                          You ask a specific question about the difference between 'hiding' and overriding' and I answered that as well as provided the documentation sections that explain it. The difference is very clear. 'Hiding' applies to STATIC methods (class methods in OR terms) that use the same method name and signature. 'Overriding' applies to INSTANCE methods that use the same method name and signature. 'Overloading' applies to INSTANCE methods that use the same method name but a DIFFERENT signature.

                          I don't see what is vague about those definitions.
                          • 10. Re: Method hiding PL/SQL
                            1009786
                            Hi, thanks for your response.

                            'Hiding' applies to STATIC methods (class methods in OR terms) that use the same method name and signature. 'Overriding' applies to INSTANCE methods that use the same method name and signature. 'Overloading' applies to INSTANCE methods that use the same method name but a DIFFERENT signature.

                            your definition is clear. it would be great if you provide an working example so that I can understand the concept in a clear way.
                            • 11. Re: Method hiding PL/SQL
                              Billy~Verreynne
                              1006783 wrote:

                              'Hiding' applies to STATIC methods (class methods in OR terms) that use the same method name and signature.
                              Does it? Hiding means in my view means private methods and private properties that only the class (object) can reference internally, and that are not visible to the caller. Oracle PL/SQL and SQL classes/objects/advance data types do not support this feature.
                              'Overriding' applies to INSTANCE methods that use the same method name and signature. 'Overloading' applies to INSTANCE methods that use the same method name but a DIFFERENT signature.
                              This is supported.
                              • 12. Re: Method hiding PL/SQL
                                vikramrathour
                                Overriding in a simple package.
                                create or replace package pkg1 as
                                     procedure p1;
                                     procedure p2;
                                end pkg1;
                                
                                create or replace package body pkg1 as
                                     procedure p1 as
                                     begin
                                     dbms_output.put_line('In main P1');
                                     end;
                                
                                     procedure p2 as
                                          procedure p1 as
                                          begin
                                          dbms_output.put_line('In P2.P1');
                                          end;
                                
                                     BEGIN
                                          dbms_output.put_line('In P2');
                                          p1;
                                          pkg1.p1;
                                     END;
                                end pkg1;
                                Now simply execute the code
                                begin
                                    pkg1.p1;     
                                    pkg1.p2;
                                end;
                                
                                In main P1
                                In P2
                                In P2.P1
                                In main P1
                                
                                Statement processed.
                                
                                0.00 seconds
                                As you can see in procedure p2 I have overridden the main P1 procedure.

                                Hope this helps.

                                Regards,
                                Vikram R
                                • 13. Re: Method hiding PL/SQL
                                  Billy~Verreynne
                                  vikramrathour wrote:

                                  As you can see in procedure p2 I have overridden the main P1 procedure.
                                  No, you have not. You have changed resolution scope. That is not the same as overriding - which is btw on o-o term and not really relevant to procedural code as you have posted.
                                  • 14. Re: Method hiding PL/SQL
                                    rp0428
                                    >
                                    1006783 wrote:
                                    'Hiding' applies to STATIC methods (class methods in OR terms) that use the same method name and signature.
                                    Does it? Hiding means in my view means private methods and private properties that only the class (object) can reference internally, and that are not visible to the caller. Oracle PL/SQL and SQL classes/objects/advance data types do not support this feature.
                                    >
                                    OP is just repeating what I said in my reply. Your use of 'hiding' is correct in terms of OR but we are discussing Oracle's use (or rather 'misuse') of the term in the Application Developer's Guide.
                                    http://docs.oracle.com/cd/B28359_01/appdev.111/b28371/adobjbas.htm#i471260

                                    See my full reply above. OP is trying to understand why Oracle used 'hiding' in reference to 'static' methods but used 'overriding' in reference to 'instance' methods.
                                    >
                                    'Overriding' applies to INSTANCE methods that use the same method name and signature. 'Overloading' applies to INSTANCE methods that use the same method name but a DIFFERENT signature.
                                    This is supported.
                                    >
                                    Again - OP was merely repeating what I said in my reply and I was still talking about the Oracle doc meaning.

                                    I still have no idea why, as a novice programmer, OP is so insistent on spending time on this particular area of Oracle functionality.
                                    1 2 3 Previous Next