Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: newbie question about Abstract methods

  1. #1
    Junior Member
    Join Date
    Jul 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default newbie question about Abstract methods

    hey, I'm working on a web application that I was given and I'm a little confused about
    some of the code in some of the classes. These are some methods in this abstract class. I don't understand
    how this post method works if the method it's calling is declared abstract. Could someone please tell me how this works?


        public final Representation post(Representation entity, Variant variant) throws ResourceException {
     
            prePostAuthorization(entity);
            if (!authorizeGet()) {
     
                return doUnauthenticatedGet(variant);
            } else {
                return doAuthenticatedPost(entity, variant);
            }
        }
     
     protected abstract boolean authorizeGet();

    Thanks


  2. #2
    Member
    Join Date
    Jun 2010
    Posts
    75
    Thanks
    7
    Thanked 1 Time in 1 Post

    Default W

    Quote Originally Posted by FailMouse View Post
    hey, I'm working on a web application that I was given and I'm a little confused about
    some of the code in some of the classes. These are some methods in this abstract class. I don't understand
    how this post method works if the method it's calling is declared abstract. Could someone please tell me how this works?


        public final Representation post(Representation entity, Variant variant) throws ResourceException {
     
            prePostAuthorization(entity);
            if (!authorizeGet()) {
     
                return doUnauthenticatedGet(variant);
            } else {
                return doAuthenticatedPost(entity, variant);
            }
        }
     
     protected abstract boolean authorizeGet();

    Thanks
    Which method is abstract?

  3. #3
    Member
    Join Date
    Jul 2010
    Posts
    45
    Thanks
    10
    Thanked 3 Times in 3 Posts

    Default Re: newbie question about Abstract methods

    Well, if the class is abstract, then you can't instantiate it. So, is it possible this abstract class is extended somewhere where the authorizeGet() method is implemented?

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,369
    Thanks
    183
    Thanked 836 Times in 779 Posts
    Blog Entries
    5

    Default Re: newbie question about Abstract methods

    Abstract methods are implemented in concrete child classes, so in the code you posted a child class would implement authorizeGet, the calling parent abstract class doesn't care how its implemented, only that it is (allows many children to implement the behavior differently, but the calling procedure can stay the same). Similar to the Template Design Pattern, where the calling class only cares about a method being implemented, not how it is implemented

Similar Threads

  1. Looping Question (newbie)
    By xdrechsler in forum Loops & Control Statements
    Replies: 13
    Last Post: July 19th, 2010, 10:12 PM
  2. Graphic Environment Abstract Methods
    By striko_514 in forum Java Theory & Questions
    Replies: 2
    Last Post: July 5th, 2010, 02:01 AM
  3. [SOLVED] Abstract Classes Help
    By SweetyStacey in forum Object Oriented Programming
    Replies: 10
    Last Post: May 6th, 2010, 07:15 AM
  4. A question about inherited methods
    By joachim89 in forum Object Oriented Programming
    Replies: 1
    Last Post: January 12th, 2010, 09:06 PM
  5. A Question Regarding Abstract Classes & Packages
    By Kerubu in forum Object Oriented Programming
    Replies: 3
    Last Post: December 21st, 2009, 01:27 PM