Late Binding

This is a discussion on Late Binding within the C# Programming forums, part of the General Programming Boards category; Forgive me if I confuse you with this question. Please ask for more details, and I will try to explain ...

  1. #1
    essence of digital xddxogm3's Avatar
    Join Date
    Sep 2003
    Posts
    589

    Late Binding

    Forgive me if I confuse you with this question.
    Please ask for more details, and I will try to explain better.

    I have a program in C# that is using an interface, base class, and derived class.

    The base class is built using an interface contract.

    The derived classes are of a similar type, all derived by the same base class, in turn using that same interface contract.

    I want to do something similar to the following.
    I understand that this code will not compile.
    I just slapped this together really quick to get my point across.
    What will happen when the base variable is printed to the screen?
    Does the base object get erased and repopulated with the second binding?

    Code:
    //base class
     
    int FooBar = 0;
     
    public Foo(int bar)
    {
       if (bar == 5)
          FooBar == bar;
    }
    Code:
    //dirived class 1
    
    int FooBar = 0;
     
    public Bla1()
    {
       base.constructor(5)
    }
    Code:
    //dirived class 2
    
    int FooBar = 0;
     
    public Bla2()
    {
       base.constructor(6)
    }
    Code:
    Foo BlaBase;
     
    BlaBase = new Bla1();
    cout<<BlaBase.FooBar;
    BlaBase = new Bla2();
    cout<<BlaBase.FooBar;
    "Hence to fight and conquer in all your battles is not supreme excellence;
    supreme excellence consists in breaking the enemy's resistance without fighting."
    Art of War Sun Tzu

  2. #2
    essence of digital xddxogm3's Avatar
    Join Date
    Sep 2003
    Posts
    589
    does late binding reinitialize the variables of the base class with default values before it repopulates with the new bound class?
    "Hence to fight and conquer in all your battles is not supreme excellence;
    supreme excellence consists in breaking the enemy's resistance without fighting."
    Art of War Sun Tzu

  3. #3
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    The FooBar variable in the derived classes is a new variable, it has nothing in common with the one in the base class. You set one variable, and print another.
    The variables in the derived classes are useless in your example.
    If you still need to access that variable, consider using a protected property.
    Oh, and this has nothing to do with late binding. C# has no late binding (yet).
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. inet_aton()... Noob needs help with sockets :|
    By Maz in forum C++ Programming
    Replies: 3
    Last Post: 11-22-2005, 03:33 PM
  2. dynamic/static binding
    By faze in forum C++ Programming
    Replies: 7
    Last Post: 07-10-2005, 12:26 PM
  3. dynamic binding
    By freethenet in forum Networking/Device Communication
    Replies: 2
    Last Post: 10-26-2004, 03:31 PM
  4. late binding with template function
    By clf in forum C++ Programming
    Replies: 1
    Last Post: 03-28-2002, 12:13 PM
  5. Static Binding & Dynamic Binding :: C++
    By kuphryn in forum C++ Programming
    Replies: 2
    Last Post: 12-31-2001, 07:51 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21