<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'Static and Dynamic binding' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'Static and Dynamic binding' posted on the 'C#' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2013 Programmers Heaven</copyright>
    <pubDate>Sat, 18 May 2013 18:17:23 -0700</pubDate>
    <lastBuildDate>Sat, 18 May 2013 18:17:23 -0700</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>Static and Dynamic binding</title>
      <link>http://www.programmersheaven.com/mb/csharp/260059/260059/static-and-dynamic-binding/</link>
      <description>Whats the difference between static and dynamic binding? I fail to understand. Could someone please explain with an example? Thanks.&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/csharp/260059/260059/static-and-dynamic-binding/</guid>
      <pubDate>Sat, 22 May 2004 05:27:58 -0700</pubDate>
      <category>C#</category>
    </item>
    <item>
      <title>Re: Static and Dynamic binding</title>
      <link>http://www.programmersheaven.com/mb/csharp/260059/260076/re-static-and-dynamic-binding/#260076</link>
      <description>: Whats the difference between static and dynamic binding? I fail to understand. Could someone please explain with an example? Thanks.&lt;br /&gt;
: &lt;br /&gt;
: &lt;br /&gt;
&lt;br /&gt;
It can all be boiled down to when the actions that take place during execution are known.&lt;br /&gt;
&lt;br /&gt;
Example 1:&lt;pre class="sourcecode"&gt;
public class MyClass
{
   public void DoSomething(){...}
}

public class MyOtherClass
{
   public MyOtherClass()
   {
      MyClass mc = new MyClass();
      mc.DoSomething();
   }
}&lt;/pre&gt;The call to DoSomething was bound statically to the instance of MyClass that we had created on the previous line.  This is known at compile time, and therefore is the only thing that can happen when this code runs.&lt;br /&gt;
&lt;br /&gt;
Example 2:&lt;pre class="sourcecode"&gt;
public abstract class WidgetBase
{
   public abstract void DoSomething();
}

public class ShinyWidget : WidgetBase
{
   public override void DoSomething()
   {
      // implementation
   }
}

public class DullWidget : WidgetBase
{
   public override void DoSomething()
   {
      // implementation
   }
}

public class MyOtherClass
{
   public void DoSomethingWithAWidget(WidgetBase widget)
   {
      widget.DoSomething();
   }
}&lt;/pre&gt;When someone instantiates MyOtherClass, they will call DoSomethingWithAWidget and pass in an instance of ShinyWidget or DullWidget.  We have no idea which one is going to be passed in, so we can't know at compile time which implementation of DoSomething is going to be called.  This is dynamic binding.&lt;br /&gt;
&lt;br /&gt;
The concept of static/dynamic binding is certainly not only applicable to abstract classes.  This is only one example.  The same concept applies to virtual methods, in many cases.&lt;pre class="sourcecode"&gt;
MyNonAbstractBaseClass bc = new ImInheritedFromMNABC();
bc.VirtalMethodName();&lt;/pre&gt;This would use dynamic binding as well.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
P.S.  I am looking forward to the next question in your study guide.  Ever think about posting the entire list to save time?&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/csharp/260059/260076/re-static-and-dynamic-binding/#260076</guid>
      <pubDate>Sat, 22 May 2004 09:20:38 -0700</pubDate>
      <category>C#</category>
    </item>
    <item>
      <title>Re: Static and Dynamic binding</title>
      <link>http://www.programmersheaven.com/mb/csharp/260059/260080/re-static-and-dynamic-binding/#260080</link>
      <description>Thank you so much for the detailed answer. Yep, I am studying C#. And the study guide sucks! You guys have been terrific with clarifying questions.&lt;br /&gt;
&lt;br /&gt;
  Here comes my next question which I noticed in the next chapter in the guide. Is it possible to pass arguments to a class declaration? Do you have any examples? Thanks in advance.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
: : Whats the difference between static and dynamic binding? I fail to understand. Could someone please explain with an example? Thanks.&lt;br /&gt;
: : &lt;br /&gt;
: : &lt;br /&gt;
: &lt;br /&gt;
: It can all be boiled down to when the actions that take place during execution are known.&lt;br /&gt;
: &lt;br /&gt;
: Example 1:&lt;pre class="sourcecode"&gt;
: public class MyClass
: {
:    public void DoSomething(){...}
: }
: 
: public class MyOtherClass
: {
:    public MyOtherClass()
:    {
:       MyClass mc = new MyClass();
:       mc.DoSomething();
:    }
: }&lt;/pre&gt;The call to DoSomething was bound statically to the instance of MyClass that we had created on the previous line.  This is known at compile time, and therefore is the only thing that can happen when this code runs.&lt;br /&gt;
: &lt;br /&gt;
: Example 2:&lt;pre class="sourcecode"&gt;
: public abstract class WidgetBase
: {
:    public abstract void DoSomething();
: }
: 
: public class ShinyWidget : WidgetBase
: {
:    public override void DoSomething()
:    {
:       // implementation
:    }
: }
: 
: public class DullWidget : WidgetBase
: {
:    public override void DoSomething()
:    {
:       // implementation
:    }
: }
: 
: public class MyOtherClass
: {
:    public void DoSomethingWithAWidget(WidgetBase widget)
:    {
:       widget.DoSomething();
:    }
: }&lt;/pre&gt;When someone instantiates MyOtherClass, they will call DoSomethingWithAWidget and pass in an instance of ShinyWidget or DullWidget.  We have no idea which one is going to be passed in, so we can't know at compile time which implementation of DoSomething is going to be called.  This is dynamic binding.&lt;br /&gt;
: &lt;br /&gt;
: The concept of static/dynamic binding is certainly not only applicable to abstract classes.  This is only one example.  The same concept applies to virtual methods, in many cases.&lt;pre class="sourcecode"&gt;
: MyNonAbstractBaseClass bc = new ImInheritedFromMNABC();
: bc.VirtalMethodName();&lt;/pre&gt;This would use dynamic binding as well.&lt;br /&gt;
: &lt;br /&gt;
: &lt;br /&gt;
: &lt;br /&gt;
: P.S.  I am looking forward to the next question in your study guide.  Ever think about posting the entire list to save time?&lt;br /&gt;
: &lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/csharp/260059/260080/re-static-and-dynamic-binding/#260080</guid>
      <pubDate>Sat, 22 May 2004 09:45:33 -0700</pubDate>
      <category>C#</category>
    </item>
    <item>
      <title>Re: Static and Dynamic binding</title>
      <link>http://www.programmersheaven.com/mb/csharp/260059/260083/re-static-and-dynamic-binding/#260083</link>
      <description>: Thank you so much for the detailed answer. Yep, I am studying C#. And the study guide sucks! You guys have been terrific with clarifying questions.&lt;br /&gt;
: &lt;br /&gt;
:   Here comes my next question which I noticed in the next chapter in the guide. Is it possible to pass arguments to a class declaration? Do you have any examples? Thanks in advance.&lt;br /&gt;
: &lt;br /&gt;
: &lt;br /&gt;
&lt;br /&gt;
We just do what we can ;)&lt;br /&gt;
&lt;br /&gt;
Yes, u can pass how many arguments u want to class.&lt;br /&gt;
When u instantiate a class the first thing the compiler does is to call the constructor of that class. If u haven't defined one yet, it will create a DEFAULT constructor following these rules:&lt;br /&gt;
&lt;br /&gt;
numeric types set to 0&lt;br /&gt;
char type set to null character&lt;br /&gt;
bool set to false&lt;br /&gt;
reference fields set to null&lt;br /&gt;
&lt;br /&gt;
U can pass arguments to a new instantiated class overriding defining a ur own constuctor and instantiating the class using the new one. Hope an example will clarify&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
public void class MyClass&lt;br /&gt;
{&lt;br /&gt;
   int Number;&lt;br /&gt;
   char Character;&lt;br /&gt;
   bool TrueOrFalse;&lt;br /&gt;
&lt;br /&gt;
   public void MyClass(int UrNumber, char UrChar, bool UrBool)&lt;br /&gt;
   {&lt;br /&gt;
      Number = UrNumber      &lt;br /&gt;
      Character = UrChar;&lt;br /&gt;
      TrueOrFalse = UrBool;&lt;br /&gt;
      &lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   public void MyClass(int UrNum)&lt;br /&gt;
   {&lt;br /&gt;
      Number = UrNum;&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public void AnotherClass&lt;br /&gt;
{&lt;br /&gt;
   MyClass Bill = new MyClass();&lt;br /&gt;
   MyClass Tom = new MyClass(12, "d", true);&lt;br /&gt;
   MyClass Peter = new MyClass(12+3);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Notice that I specified two different constructors in MyClass.&lt;br /&gt;
&lt;br /&gt;
In AnotherClass u instantiate 3 classes (Bill, Tom and Peter) and u use a different constructor for every one of them. What the compiler do to choose which one to select is looking at the signature (the parameters passed). What defines uniquely a signature is the order and the type of the parameters passed. (that means u cannot have two constructors passing both 2 int).&lt;br /&gt;
&lt;br /&gt;
Creating Bill u call the default constructor obtaining these values:&lt;br /&gt;
Bill.Number = 0&lt;br /&gt;
Bill.Character = null character&lt;br /&gt;
Bill.TrueOrFalse = false&lt;br /&gt;
&lt;br /&gt;
(note that u don't have to define the default constructor)&lt;br /&gt;
&lt;br /&gt;
Creating Tom u call the first constructor (the one with 3 parameters) and give its variables the following values:&lt;br /&gt;
Tom.Number = 12&lt;br /&gt;
Tom.Character = d&lt;br /&gt;
Tom.TrueOrFalse = true&lt;br /&gt;
&lt;br /&gt;
Creating Peter u use the second constructor u defined. What u have is to set the variables u explcitly chose to the value passed with the parameter and have the others set with the default constructor rules&lt;br /&gt;
Peter.Number = 15&lt;br /&gt;
Peter.Character = null character&lt;br /&gt;
Peter.TrueOrFalse = false&lt;br /&gt;
&lt;br /&gt;
Plz note that u can pass as a parameter an expression too, which can be also of a type calculated run-time&lt;br /&gt;
i.e   x+y&lt;br /&gt;
where x and y are variables u declared and assigned a value before&lt;br /&gt;
&lt;br /&gt;
Keep on practicing...and maybe change manual ;)&lt;br /&gt;
&lt;br /&gt;
ing_gigio&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/csharp/260059/260083/re-static-and-dynamic-binding/#260083</guid>
      <pubDate>Sat, 22 May 2004 10:20:35 -0700</pubDate>
      <category>C#</category>
    </item>
    <item>
      <title>Re: Static and Dynamic binding</title>
      <link>http://www.programmersheaven.com/mb/csharp/260059/260088/re-static-and-dynamic-binding/#260088</link>
      <description>As a follow up of your answer I have the following question:&lt;br /&gt;
Can I have a class a private member of another class?&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
: : Thank you so much for the detailed answer. Yep, I am studying C#. And the study guide sucks! You guys have been terrific with clarifying questions.&lt;br /&gt;
: : &lt;br /&gt;
: :   Here comes my next question which I noticed in the next chapter in the guide. Is it possible to pass arguments to a class declaration? Do you have any examples? Thanks in advance.&lt;br /&gt;
: : &lt;br /&gt;
: : &lt;br /&gt;
: &lt;br /&gt;
: We just do what we can ;)&lt;br /&gt;
: &lt;br /&gt;
: Yes, u can pass how many arguments u want to class.&lt;br /&gt;
: When u instantiate a class the first thing the compiler does is to call the constructor of that class. If u haven't defined one yet, it will create a DEFAULT constructor following these rules:&lt;br /&gt;
: &lt;br /&gt;
: numeric types set to 0&lt;br /&gt;
: char type set to null character&lt;br /&gt;
: bool set to false&lt;br /&gt;
: reference fields set to null&lt;br /&gt;
: &lt;br /&gt;
: U can pass arguments to a new instantiated class overriding defining a ur own constuctor and instantiating the class using the new one. Hope an example will clarify&lt;br /&gt;
: &lt;br /&gt;
: &lt;br /&gt;
: public void class MyClass&lt;br /&gt;
: {&lt;br /&gt;
:    int Number;&lt;br /&gt;
:    char Character;&lt;br /&gt;
:    bool TrueOrFalse;&lt;br /&gt;
: &lt;br /&gt;
:    public void MyClass(int UrNumber, char UrChar, bool UrBool)&lt;br /&gt;
:    {&lt;br /&gt;
:       Number = UrNumber      &lt;br /&gt;
:       Character = UrChar;&lt;br /&gt;
:       TrueOrFalse = UrBool;&lt;br /&gt;
:       &lt;br /&gt;
:    }&lt;br /&gt;
: &lt;br /&gt;
:    public void MyClass(int UrNum)&lt;br /&gt;
:    {&lt;br /&gt;
:       Number = UrNum;&lt;br /&gt;
:    }&lt;br /&gt;
: }&lt;br /&gt;
: &lt;br /&gt;
: public void AnotherClass&lt;br /&gt;
: {&lt;br /&gt;
:    MyClass Bill = new MyClass();&lt;br /&gt;
:    MyClass Tom = new MyClass(12, "d", true);&lt;br /&gt;
:    MyClass Peter = new MyClass(12+3);&lt;br /&gt;
: }&lt;br /&gt;
: &lt;br /&gt;
: &lt;br /&gt;
: Notice that I specified two different constructors in MyClass.&lt;br /&gt;
: &lt;br /&gt;
: In AnotherClass u instantiate 3 classes (Bill, Tom and Peter) and u use a different constructor for every one of them. What the compiler do to choose which one to select is looking at the signature (the parameters passed). What defines uniquely a signature is the order and the type of the parameters passed. (that means u cannot have two constructors passing both 2 int).&lt;br /&gt;
: &lt;br /&gt;
: Creating Bill u call the default constructor obtaining these values:&lt;br /&gt;
: Bill.Number = 0&lt;br /&gt;
: Bill.Character = null character&lt;br /&gt;
: Bill.TrueOrFalse = false&lt;br /&gt;
: &lt;br /&gt;
: (note that u don't have to define the default constructor)&lt;br /&gt;
: &lt;br /&gt;
: Creating Tom u call the first constructor (the one with 3 parameters) and give its variables the following values:&lt;br /&gt;
: Tom.Number = 12&lt;br /&gt;
: Tom.Character = d&lt;br /&gt;
: Tom.TrueOrFalse = true&lt;br /&gt;
: &lt;br /&gt;
: Creating Peter u use the second constructor u defined. What u have is to set the variables u explcitly chose to the value passed with the parameter and have the others set with the default constructor rules&lt;br /&gt;
: Peter.Number = 15&lt;br /&gt;
: Peter.Character = null character&lt;br /&gt;
: Peter.TrueOrFalse = false&lt;br /&gt;
: &lt;br /&gt;
: Plz note that u can pass as a parameter an expression too, which can be also of a type calculated run-time&lt;br /&gt;
: i.e   x+y&lt;br /&gt;
: where x and y are variables u declared and assigned a value before&lt;br /&gt;
: &lt;br /&gt;
: Keep on practicing...and maybe change manual ;)&lt;br /&gt;
: &lt;br /&gt;
: ing_gigio&lt;br /&gt;
: &lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/csharp/260059/260088/re-static-and-dynamic-binding/#260088</guid>
      <pubDate>Sat, 22 May 2004 11:14:04 -0700</pubDate>
      <category>C#</category>
    </item>
    <item>
      <title>Re: Static and Dynamic binding</title>
      <link>http://www.programmersheaven.com/mb/csharp/260059/260091/re-static-and-dynamic-binding/#260091</link>
      <description>: As a follow up of your answer I have the following question:&lt;br /&gt;
: Can I have a class a private member of another class?&lt;br /&gt;
: &lt;br /&gt;
&lt;br /&gt;
what do u exactly mean with "have" ? U mean using as an external or having in its body as one of the methods?&lt;br /&gt;
&lt;br /&gt;
In the first case u cannot do anything... Maybe u can use delegation...but it's somthing I'm still studyng..I'll let u know soon ;)&lt;br /&gt;
&lt;br /&gt;
What I want to say is that u cannot have a class MyClass implementing a private method named for instance OnePrivateMethod and write something like this&lt;br /&gt;
&lt;br /&gt;
public class User&lt;br /&gt;
{&lt;br /&gt;
MyClass Cippalippa = new MyClass();&lt;br /&gt;
cippalippa.OnePrivateMethod;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
defining a method private u forbid any access to it.&lt;br /&gt;
&lt;br /&gt;
The only exception to this is if the class which is calling is a derived class.&lt;br /&gt;
public class UserTwo : MyClass&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
In this case u have that UserTwo can both use the method of the parent class&lt;br /&gt;
&lt;br /&gt;
public class UserTwo:MyClass&lt;br /&gt;
{&lt;br /&gt;
base.OnePrivateMethod;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
or use the method as part of its body&lt;br /&gt;
&lt;br /&gt;
public class UserTwo:MyClass&lt;br /&gt;
{&lt;br /&gt;
this.OnePrivateMethod;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
This is because with inheritance the derived class inherites all the variables and method of the parent class and can implements some new ones in addition. (this idea behind it is to have a more easy-to-understand code and help u writing less...u don't have to write twice the same stuff! ;)&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/csharp/260059/260091/re-static-and-dynamic-binding/#260091</guid>
      <pubDate>Sat, 22 May 2004 11:40:38 -0700</pubDate>
      <category>C#</category>
    </item>
    <item>
      <title>Re: Static and Dynamic binding</title>
      <link>http://www.programmersheaven.com/mb/csharp/260059/419303/re-static-and-dynamic-binding/#419303</link>
      <description>Check this link related to dynamic binding in C#&lt;br /&gt;
&lt;a href="http://www.mindstick.com/Forum/48/What%20is%20dynamic%20binding%20in%20C#"&gt;&lt;/a&gt;&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/csharp/260059/419303/re-static-and-dynamic-binding/#419303</guid>
      <pubDate>Mon, 25 Oct 2010 02:55:50 -0700</pubDate>
      <category>C#</category>
    </item>
  </channel>
</rss>