Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19
Extended classes
Results 1 to 3 of 3

Thread: Extended classes

  1. #1
    Mentor
    Join Date
    Jul 2001
    Posts
    1,666

    Extended classes

    Sorry for the longwinded explanation, I can't think how to make it more simple.
    I've got a class called Account. Its basically a bank account. Then I have another class calles SavingsAccount which just extends Account. Within the SavingsAccount there is a method called getTotalInterest. This just returns a long.
    I have another class called Branch. Inside the Branch class is an array, accounts, which holds all SavingsAccount objects and all Account objects. I need to write a method which totals the interest within the array, ie the interest in all the SavingsAccount objects.

    Now for the question, is there a method that allows me to check if a specific object within the array is a SavingsAccount object, or just a plain Account object. Or is there a way to check if the object contains a specific method?
    Cheers
    CP

  2. #2
    Associate
    Join Date
    Dec 2002
    Posts
    13

    Re:Extended classes

    [quote author=CP link=board=9;threadid=7019;start=0#65165 date=1052890874]Now for the question, is there a method that allows me to check if a specific object within the array is a SavingsAccount object, or just a plain Account object. Or is there a way to check if the object contains a specific method?[/quote]

    Some languages implement RTTI (Run Time Type Information) to do this. What language are you using?

    You can add this functionality (partly?) yourself, by adding virtual functions that return some identifier for the specific object. Something like:
    Code:
    class Account
    {
       virtual string isA() { return "Account"; )
    }
    
    class SavingsAccount extends Account
    {
       virtual string isA() { return "SavingsAccount"; )
    }
    And then see what string "isA() " returns...


  3. #3
    Mentor
    Join Date
    Jul 2001
    Posts
    1,666

    Re:Extended classes

    Oops, I'm using java. I found out how to do what I wanted. If I have the object that I want to know what it is I can create a new Class, which is that objects class. And then there is a method called getName which tells me what kind of class it is, so I know whether or not I can do what I want to do.
    CP

Similar Threads

  1. Tc classes MRTG
    By Net_Spy in forum Linux - Hardware, Networking & Security
    Replies: 1
    Last Post: 01-31-2009, 07:21 PM
  2. How can I unmount Swap and Extended on the Ubuntu 5.10 Live Cd
    By cheetahman in forum Linux - Software, Applications & Programming
    Replies: 6
    Last Post: 03-28-2006, 07:41 PM
  3. Replies: 3
    Last Post: 03-27-2006, 07:08 PM
  4. Allow classes to create own forum/posts
    By Blaqb0x in forum Announcements and Suggestions
    Replies: 5
    Last Post: 05-22-2002, 04:21 AM
  5. Classes of 2002
    By ndogg in forum General Chat
    Replies: 4
    Last Post: 05-20-2002, 10:09 AM

Bookmarks

Posting Permissions

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