I need a little help here with extends.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sandyw
    New Member
    • Mar 2007
    • 122

    I need a little help here with extends.

    I need a little help here with extends.

    I have three class
    1. EventsClass
    2. TicketClass I have the extends to EventsClass
    3. BuyerClass. I have the extends to EventsClass

    All three class have Accessors and Mutator Methods.
    When I'm trying to create the Public buyterTracker
    I get an error but it does not tell me what kind of error
    Can someone help me please

    Code:
    lass buyerTracker extends EventClass{
    	private String buyername;
    	private String buyeraddr;
    
    public [B]buyerTracker(String bn, String ba)[/B] {
    		this.buyername = bn;
    		this.buyeraddr = ba;
    
    	}
    
    	// accessors
    	public String getBuyname() {
    		return buyername;
    	}
    
    	public String getBuyeraddr() {
    		return buyeraddr;
    	}
    
    	public void setBuyername(String bn) {
    		buyername = bn;
    	}
    
    	public void setBuyerAddr(String ba) {
    		buyeraddr = ba;
    	}
    
    	public String toString() {
    	    return "(" + buyername + "," + buyeraddr + ")";
    	}
    }
    Thanks
    Sandy
  • sandyw
    New Member
    • Mar 2007
    • 122

    #2
    Originally posted by sandyw
    I need a little help here with extends.

    I have three class
    1. EventsClass
    2. TicketClass I have the extends to EventsClass
    3. BuyerClass. I have the extends to EventsClass

    All three class have Accessors and Mutator Methods.
    When I'm trying to create the Public buyterTracker
    I get an error but it does not tell me what kind of error
    Can someone help me please

    Code:
    class buyerTracker extends EventClass{
    	private String buyername;
    	private String buyeraddr;
    
    public [B]buyerTracker(String bn, String ba)[/B] {
    		this.buyername = bn;
    		this.buyeraddr = ba;
    
    	}
    
    	// accessors
    	public String getBuyname() {
    		return buyername;
    	}
    
    	public String getBuyeraddr() {
    		return buyeraddr;
    	}
    
    	public void setBuyername(String bn) {
    		buyername = bn;
    	}
    
    	public void setBuyerAddr(String ba) {
    		buyeraddr = ba;
    	}
    
    	public String toString() {
    	    return "(" + buyername + "," + buyeraddr + ")";
    	}
    }
    Thanks
    Sandy
    lass is suppost be class

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #3
      Did you read my previous tip of the week? It's in the Articles section now and
      it discusses the Liskov Substitution Principle a bit.

      There is no way you can come up with a TicketClass that *is* an EventClass
      nor *is* a BuyerClass an EventClass. So inheritance that way is a total nono.
      Did you read my latest reply in your other thread where you mentioned this
      exact same subject?

      An EventClass *has* Tickets (TicketClass) and the same holds for Buyer(Class).

      kind regards,

      Jos

      Comment

      • sandyw
        New Member
        • Mar 2007
        • 122

        #4
        Originally posted by JosAH
        Did you read my previous tip of the week? It's in the Articles section now and
        it discusses the Liskov Substitution Principle a bit.

        There is no way you can come up with a TicketClass that *is* an EventClass
        nor *is* a BuyerClass an EventClass. So inheritance that way is a total nono.
        Did you read my latest reply in your other thread where you mentioned this
        exact same subject?

        An EventClass *has* Tickets (TicketClass) and the same holds for Buyer(Class).

        kind regards,

        Jos
        They say this is the hard part getting the class right.
        so if I have 3 class
        1. TransferClass.( parent class)
        2. EventClass extends TransferClass.
        3. TicketClass extends EventClass.
        4. BuyerClass extends TicketClass.

        Sorry Jos but what will Transfer class do. Holds the infor from all the class?
        Does
        EventClass hold EventID, Concent, Seat Layout
        TicketClass holds Date, time, price, Seat Number
        BuyerClass holds Buyer name and address.

        Sorry to be a pain in the you know what
        thanks
        Sandy
        Ps I did read your article...

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          Originally posted by sandyw
          They say this is the hard part getting the class right.
          so if I have 3 class
          1. TransferClass.( parent class)
          2. EventClass extends TransferClass.
          3. TicketClass extends EventClass.
          4. BuyerClass extends TicketClass.
          ... and that makes four ;-)

          Think of real events, say a theatre show. The event *has* tickets for sale and
          buyers can buy tickets. Both the events and the buyers *have* zero or more
          tickets. When a buyer buys a ticket s/he owns the ticket. Some tracking
          mechanism or class associates tickets with buyers. The ticket has to know
          about the event (a ticket is/was owned by an event and was/is possibly owned
          by a buyer). That notion is encapsulated by a "transfer".

          In this entire little scenario there is no inheritance present at all. Especially not
          when you take that Liskov thing into account: a buyer *isn't* a ticket and a
          ticket *isn't* a theatre show.

          kind regards,

          Jos

          ps. no need to apologize for anything; try to be egoless when it comes to
          class and class hierarchy design; it works better that way.

          Comment

          Working...