Thread: Packages

Results 1 to 3 of 3
  1. #1 Packages 
    Registered Member
    Join Date
    Jan 2009
    Posts
    525
    Thanks given
    1
    Thanks received
    8
    Rep Power
    29
    I'm thinking about handling my skills and I was wondering if I for example did this :

    Code:
    public class Flecthing extends Client {
    Will the class flecthing then have all the methods from the client class?
    Reply With Quote  
     

  2. #2  
    Registered Member
    PSNB's Avatar
    Join Date
    Aug 2009
    Posts
    885
    Thanks given
    8
    Thanks received
    103
    Rep Power
    590
    It will have all of the methods from the client class (That have a default level access or higher).

    But this is definitely not what you're looking for. All this is doing is creating a new Client object and adding new methods to it. What I mean is if you were to do this, then Fletching would need to be runnable, have it's own thread, socket, etc.

    What you want to do is pass a client parameter onto the Fletching class, and use that to handle everything.

    Code:
    public class Fletching {
    
        /**
         * The Player.
         */
        private final Client client;
    
        /**
         * Creates a new Fletching instance.
         * @param client The client to create this instance for.
         */
        public Fletching(Client client) {
            this.client = client;
        }
    
        /**
         * Strings a bow.
         */
        public void stringBow(int bowId) {
            //TODO - String bow, delete from inventory, etc.
        }
    
    }
    Note, however that I only recommend doing this if you're going to handle all fletching-related variables and methods in this class. If you're just going to handle them in the Client class, then just access them through the Fletching class, I recommend using this approach instead.

    Code:
    public class Fletching {
    
        public static void stringBow(int bowId, Client client) {
            //TODO - String bow, delete from inventory, etc.
        }
    
    }
    The difference between the two is that the first passes on a Client parameter to the constructor, and stores it in the class. This allows for you to use that Client instance rather than passing one along to each method. It also allows you to store the variables for Fletching in the class.

    The second approach, on the other hand passes nothing on to the constructor, and each of the methods requires a Client parameter. This should only be used if you're handling the Fletching variables in the Client class.
    Reply With Quote  
     

  3. #3  
    Registered Member
    Join Date
    Jan 2009
    Posts
    525
    Thanks given
    1
    Thanks received
    8
    Rep Power
    29
    So the client parameter I should use if I would handle excactly everything, even the itemOnItem?
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •