Hi, To all the programmers who is working in .net should know some of the facts. Well, .Net is not an Operating System. Its also not a general purpose software package. Its just somewhat functionality for the programmers to build their solution in the most constructive and intellegent way ever.
Just to tell you the truth, most of the codes in .Net environment resembles with the JAVA coding as if some people coming from Java would find it as to their native language.
.NET is a Framework that loads into your operating system, which you need not to load in the later virsions of windows like Windows 2003 server or Just a new release of Windows Vista. As it is going to be added as a component in the next generation of windows.
Now, What is the .Net all about??? Well, Its a framework that supports Common Language Runtime (CLR). As the name suggests, Common Language Runtime will be something that will run a native code for all the programming languages provided within the Architecture. Just for example, I would rather say that integer of VB.NET and int of C# are same, as they are both object of the Int32 class. And because of the generation of Intermediate language (Byte code + metadata ) in assembly produced as output during compilation is again compiled by JIT compiler( for those of you came from JAVA must know this). This enables you to bind two assemblies during runtime. Thats what is called basically interlanguage communication.
Now then what is language independence??
Well, to tell you about language Independence, .Net is not at all efficient in that. Just Microsoft built their own version of languages like C++, J# (for Java), C#, VB etc that can communicate between each other. Afterall J#, even if they resembles with JAVA is not purely Java.. Thus, the word may look to you somewhat fake.
Now what is the most prospective part of .NET?
Now, with the growing Internet, ASP.NET may be the most important part of .NET technology.
Well, ASP.NET has a new technology where the controls reside server side. You dont bother to use traditional client side controls. In .NET technology as there is a provision of runtime building of machine codes, a web server can directly compile and transmit codes to the browser during runtime. This is , I think the most approved and widely accepted part of .NET.
NEW things of .NET?
well, during the last two years , Microsoft is constantly changing the .NET technology, that may not be good for a settled programer. Well, first of all, in .NET 2003 Microsoft changed some features and also addes some new things. Well, new things are good, but changing the existing in such a quick succession is not at all good from programmers point of view. Again, in 2005, Microsoft publishes the new release of VISUAL STUDIO.NET 8 . This is a completely new environment. It have new releases of controls, the IDE is also different. Thats not what we all wanted as a programmer. What do you say????
Now, Microsoft is also increasing its scope.. One of the most important feature that is just now introduced is AJAX. Well, the name is what can be said as Asynchronous Java Script with XML.
What is AJAX???
Now, AJAX is not a technology. Its a new technique that can be embeded in your existing ASP.NET application to enable you partially update the web page without totally refresing the page. The introduction of ATLAS controls are also a great achievement. This is the latest trend of the ASP.NET programmers. Just you can see some of the latest updates of yahoo, as in the home page after signing in you can see the mails directly in the home page. Keep a watch. Also the most important findings may be for gmail users. You all dont have to refresh the page for an updation of the page.
In gmail, a chatting environment is also created with the use of ajax, may be...
Now I request to add on comments to my postings so that I can write more on this topic...
Thanks in advance......
Monday, October 13, 2008
.NET Code Construct
Okey... Lets proceed our discussion a bit more.. In my previous topic posted, I have gave you a brief Idea of the whole thing where the technology is facing... Now I will go a bit indepth... and show you how to use the existing technology of .NET to built the most beautiful and fully featured software applications.
To start with VB.NET, I must say, its far far better from the previous version of VB. It is fully Object Oriented Programming Language with all the functionalities of OOPS, so that all the programmers feel better in this language. Also with the full support of .NET Framework, you will have to do only a few codes in this environment.
To work with VB.NET you need the Visual Studio .NET in your machine. Lets start with that one. Go to File->New-Project. Give Location of your application and choose windows Application from the right hand side of the dialog box while choosing the language VB in the left. After you click on open, it should open a new blank form in front of you...
Well, How does everything happened so fast without writing not even a single line of code. Well, Microsoft did it for us already. In case of JAVA you find a Frame class already built in the java.awt package. Here also in case of microsoft's VB, it is just a class already built in by microsoft called Form Class.
Actually, Just similar to JAVA, microsoft has made a hierarchy of classes and stored in a number of namespaces. Namespaces means just a scope that holds classes and other namespaces. The concept is just similar to our so called folder hierarchy... Suppose we think a namespace as a folder and a class a file. So there is drives which we call roots, just similarly here also there is a root namespace called System. Everything that corresponds to system, will be stored within this package. Under this there are other namespaces too.. like Data, Windows etc... Every namespace holds classes or other namespaces. Just similar to the concept that every folder holds other folders or files.
Now coming to our point whenever I open the project, I saw a new blank form in front of me... Its just inherited from a class System.Windows.Forms.Form, so everything defined within the form will come to this form. Well well, thats just a flick of a second, that all the associated properties and functions in the class comes to your place. Isnt it beautiful.
So your form1 is inherited from the already created form with all the listeners of events associated already. Now you can start adding other controls.
Microsoft had created a separate region and made everything within that area... This is Windows Designer Generated Code. Here you will find Sub new() which is nothing but a constructor of your class, so it gets automatically called whenever you run your application, means when you create actual object. The initializecomponent function will initialize the components just before the object comes into work, and all the settings that you have modified with, will be in place properly. Thus whenever you run, everything that you made in this form gets displayed.
Now lets work with some of the controls. In the left hand side you will find a toolbox, where you get all the tools that you require to place in your form. Those are called controls... So whenever you drag any control in your form, a new object of that class is created and it gets displayed over your form.... Is it that much simple... What do you think. ??? Its not.. It looks very simple, but it actually a bit more. I must say, in form class, there is an array called controls array. Now this array is very helpful. In VB.NET everything that you add in this array will be displayed on the form, so within the class form there is something I am sure that draws the entire thing in the form if you have added the same in Controls array.
So whenever you drag one control, say its a button It creates two lines, in general,
Friend withevents button1 as button
Controls.add(button1)
Now withevents keyword is very helpful, in regards to event handling. Whenever we create an object normally, it is not associated with any action listener of the events. Now withevents will automatically add up all the listeners to the control and everything will come under your way....
Otherwise if you create one button without withevents keyword, you need to manually add a listener to the control
Addhandler button1.click, new EventHandler(Addressof button1_click)
that is, we are adding a listener and whenever it occurs, it will call an eventhandler button1_click which is an eventhandler procudure. Otherwise withevents keyword will automatically add up all the events with the button class and call a blank event procedure.
Now lets us look to the solution explorer. You will find a solution explorer, a window, just if you dont see one, go to view and find solution explorer there. After you get it, you will see a hirerchy there also, the first line suggests the name of your solution, means a number of projects can be added up for a single solution. This solution will be written in a file with .SLN extension.
Next, Line is the name of your project. Under this project, the first thing you notice is some references, they are some locations which you can call directly, they are references added automatically, like System.Windows.Forms so to call Form class under this namespace without giving the whole path you can use just Form and get the class name.
After references, there is a file called AssemblyInfo.VB.
Now if you open this file, you will get the metadata associated with your project, mainly class id of your application and many more. The next option is your form, to create a form Microsoft creates two files, one is for code with .VB extension and other is for visual interface with .RESX extension. So if you delete .RESX file from the location, your application looses visual interface. Ok.
The property window helps us to change the default properties of controls, so whenever I select a control, the properties window will change its content dramatically and display all the associated properties associated with that particular control.
Now let us create a button..
In a blank form drag a button, and then double click on the button placed in the form, the code window appears, Write the following
private sub button1_click(Byval sender as System.Object, ByVal e as System.EventArgs)Handles Button1.click
MessageBox.Show("Hello Welcome to the World of VB.NET")
End Sub
[EXPLANATION]
Now if you run your application, and click on the button, it will show a messagebox in front of you.
Now to understand an event procudure, its just like normal procedure, but with some strict rules, Its signature is just similar to what I have shown, otherwise it will not be treated as an event procedure one... So for every event procedure , you must write two arguments, The first one is Object type, now this argument will take the actual object inside your event procedure which have generated the event. So here button1 and sender is the same thing if you are writing within the block.Now what for, just in the very next you have seen handles keyword, its the list of events associated with the event procedure. So now here, one event procedure can handle multiple events. The second argument will take event related information. We will discuss them later on.
Now lets take another textbox in the form and add textbox1.click just after handles button1.click after giving a comma... so that it looks like this
private sub button1_click(Byval sender as System.Object, ByVal e as System.EventArgs)Handles Button1.click,textbox1.click
if typeof(sender) is Button then
MessageBox.Show("Hello You clicked a button")
else if typeof(sender) is TextBox then
MessageBox.Show("Hello You clicked a Textbox")
End Sub
Just in this case you can detect if the procedure is invoked using textbox.click of button1.click. Isnt it look handy.
Now if you look at the messagebox class,there is a shared method show, when called with an argument of string type will print the string in a messagebox...
The return type of show function is DialogResult...
So if I want to trap the result of Messagebox.show we can trap by creating an object of DialogResult
Dim result as DialogResult
result=Messagebox.show("Message","Caption",MessageboxButtons.OKCANCEL)
if result=DialogResult.OK then
Me.Text="OK Clicked"
else
Me.Text="CANCEL Clicked"
end if
Here me represents the Current class, just like this pointer .... of C++ or C#. So the text of the title bar of your form will get changed.
Now Let us create another form, to create a form, right click on the project icon of the solution explorer(Second line of Solution explorer hierarchy) and add->new Item. From the dialog box choose form and click open. A blank for comes in a new tab. Just drag a label here and Write something in its text proerty of properties window.
Nest go to the form1 again, drag another button Let it be button2 and write the code below in the code window
public sub button2_click(ByVal sender as Object, ByVal e as EventArgs) Handles Button2.click
Dim f as new Form2
f.show()
Me.hide()
End Sub
Now whenever you run the application and click on button2, a new form will be displayed in front of you.. So by this way you can navigate from one form to the other. The first line creates a new object for form2 class, next line shows the form, making Form2.Visible=true and Me means Form1.Visible=False. Just to make form2 as startup, you again right click on the project of the solution explorer and go to properties. Change the startup object to form2 and start running.. The form2 will be now your startup form...
Now I think you all can start working with some codes with VB.NET, I will proceed with more discussions in my next posts, so keep watching my posts...
Thanks a lot
To start with VB.NET, I must say, its far far better from the previous version of VB. It is fully Object Oriented Programming Language with all the functionalities of OOPS, so that all the programmers feel better in this language. Also with the full support of .NET Framework, you will have to do only a few codes in this environment.
To work with VB.NET you need the Visual Studio .NET in your machine. Lets start with that one. Go to File->New-Project. Give Location of your application and choose windows Application from the right hand side of the dialog box while choosing the language VB in the left. After you click on open, it should open a new blank form in front of you...
Well, How does everything happened so fast without writing not even a single line of code. Well, Microsoft did it for us already. In case of JAVA you find a Frame class already built in the java.awt package. Here also in case of microsoft's VB, it is just a class already built in by microsoft called Form Class.
Actually, Just similar to JAVA, microsoft has made a hierarchy of classes and stored in a number of namespaces. Namespaces means just a scope that holds classes and other namespaces. The concept is just similar to our so called folder hierarchy... Suppose we think a namespace as a folder and a class a file. So there is drives which we call roots, just similarly here also there is a root namespace called System. Everything that corresponds to system, will be stored within this package. Under this there are other namespaces too.. like Data, Windows etc... Every namespace holds classes or other namespaces. Just similar to the concept that every folder holds other folders or files.
Now coming to our point whenever I open the project, I saw a new blank form in front of me... Its just inherited from a class System.Windows.Forms.Form, so everything defined within the form will come to this form. Well well, thats just a flick of a second, that all the associated properties and functions in the class comes to your place. Isnt it beautiful.
So your form1 is inherited from the already created form with all the listeners of events associated already. Now you can start adding other controls.
Microsoft had created a separate region and made everything within that area... This is Windows Designer Generated Code. Here you will find Sub new() which is nothing but a constructor of your class, so it gets automatically called whenever you run your application, means when you create actual object. The initializecomponent function will initialize the components just before the object comes into work, and all the settings that you have modified with, will be in place properly. Thus whenever you run, everything that you made in this form gets displayed.
Now lets work with some of the controls. In the left hand side you will find a toolbox, where you get all the tools that you require to place in your form. Those are called controls... So whenever you drag any control in your form, a new object of that class is created and it gets displayed over your form.... Is it that much simple... What do you think. ??? Its not.. It looks very simple, but it actually a bit more. I must say, in form class, there is an array called controls array. Now this array is very helpful. In VB.NET everything that you add in this array will be displayed on the form, so within the class form there is something I am sure that draws the entire thing in the form if you have added the same in Controls array.
So whenever you drag one control, say its a button It creates two lines, in general,
Friend withevents button1 as button
Controls.add(button1)
Now withevents keyword is very helpful, in regards to event handling. Whenever we create an object normally, it is not associated with any action listener of the events. Now withevents will automatically add up all the listeners to the control and everything will come under your way....
Otherwise if you create one button without withevents keyword, you need to manually add a listener to the control
Addhandler button1.click, new EventHandler(Addressof button1_click)
that is, we are adding a listener and whenever it occurs, it will call an eventhandler button1_click which is an eventhandler procudure. Otherwise withevents keyword will automatically add up all the events with the button class and call a blank event procedure.
Now lets us look to the solution explorer. You will find a solution explorer, a window, just if you dont see one, go to view and find solution explorer there. After you get it, you will see a hirerchy there also, the first line suggests the name of your solution, means a number of projects can be added up for a single solution. This solution will be written in a file with .SLN extension.
Next, Line is the name of your project. Under this project, the first thing you notice is some references, they are some locations which you can call directly, they are references added automatically, like System.Windows.Forms so to call Form class under this namespace without giving the whole path you can use just Form and get the class name.
After references, there is a file called AssemblyInfo.VB.
Now if you open this file, you will get the metadata associated with your project, mainly class id of your application and many more. The next option is your form, to create a form Microsoft creates two files, one is for code with .VB extension and other is for visual interface with .RESX extension. So if you delete .RESX file from the location, your application looses visual interface. Ok.
The property window helps us to change the default properties of controls, so whenever I select a control, the properties window will change its content dramatically and display all the associated properties associated with that particular control.
Now let us create a button..
In a blank form drag a button, and then double click on the button placed in the form, the code window appears, Write the following
private sub button1_click(Byval sender as System.Object, ByVal e as System.EventArgs)Handles Button1.click
MessageBox.Show("Hello Welcome to the World of VB.NET")
End Sub
[EXPLANATION]
Now if you run your application, and click on the button, it will show a messagebox in front of you.
Now to understand an event procudure, its just like normal procedure, but with some strict rules, Its signature is just similar to what I have shown, otherwise it will not be treated as an event procedure one... So for every event procedure , you must write two arguments, The first one is Object type, now this argument will take the actual object inside your event procedure which have generated the event. So here button1 and sender is the same thing if you are writing within the block.Now what for, just in the very next you have seen handles keyword, its the list of events associated with the event procedure. So now here, one event procedure can handle multiple events. The second argument will take event related information. We will discuss them later on.
Now lets take another textbox in the form and add textbox1.click just after handles button1.click after giving a comma... so that it looks like this
private sub button1_click(Byval sender as System.Object, ByVal e as System.EventArgs)Handles Button1.click,textbox1.click
if typeof(sender) is Button then
MessageBox.Show("Hello You clicked a button")
else if typeof(sender) is TextBox then
MessageBox.Show("Hello You clicked a Textbox")
End Sub
Just in this case you can detect if the procedure is invoked using textbox.click of button1.click. Isnt it look handy.
Now if you look at the messagebox class,there is a shared method show, when called with an argument of string type will print the string in a messagebox...
The return type of show function is DialogResult...
So if I want to trap the result of Messagebox.show we can trap by creating an object of DialogResult
Dim result as DialogResult
result=Messagebox.show("Message","Caption",MessageboxButtons.OKCANCEL)
if result=DialogResult.OK then
Me.Text="OK Clicked"
else
Me.Text="CANCEL Clicked"
end if
Here me represents the Current class, just like this pointer .... of C++ or C#. So the text of the title bar of your form will get changed.
Now Let us create another form, to create a form, right click on the project icon of the solution explorer(Second line of Solution explorer hierarchy) and add->new Item. From the dialog box choose form and click open. A blank for comes in a new tab. Just drag a label here and Write something in its text proerty of properties window.
Nest go to the form1 again, drag another button Let it be button2 and write the code below in the code window
public sub button2_click(ByVal sender as Object, ByVal e as EventArgs) Handles Button2.click
Dim f as new Form2
f.show()
Me.hide()
End Sub
Now whenever you run the application and click on button2, a new form will be displayed in front of you.. So by this way you can navigate from one form to the other. The first line creates a new object for form2 class, next line shows the form, making Form2.Visible=true and Me means Form1.Visible=False. Just to make form2 as startup, you again right click on the project of the solution explorer and go to properties. Change the startup object to form2 and start running.. The form2 will be now your startup form...
Now I think you all can start working with some codes with VB.NET, I will proceed with more discussions in my next posts, so keep watching my posts...
Thanks a lot
Sunday, October 12, 2008
Inheritence and Polymorphism
Well, now I would like to make some more clear ideas about what coding is when you are working in VB.NET.
As I have already told you, the first line just after the class name, you will be getting the inherits part. This inherits part making our task of getting a new form much easier. It would be worthy enough to get a well designed form just with a click of mouse. Isnt it. Its what we all know about the famous feature of any OOPS based language. In case of JAVA we have to derive from Frame class whereas here it is Form class. Both are the same thing.
OOPS concept:
1. Inheritence: Inheritence is the process of getting all the properties of the base class within the new class that you are deriving from. Well, its just a shortcut of getting everything pre-defined or created. So it just ensures reusability. Nothing else. Just once a class is defined, it can be inherited instantly to another class and can be used with their function whenever you require to use them. Only the exception if you define a class as NOTINHERITABLE, that class cannot be inherited. So hey hey.. until you are hard enough to give your code to other programmers, you can surely make your code Inheritable... Now lets look at the code below. public class A
public void show()
msgbox ("Hello") ' Messagebox function defined already within your scope...
end sub
end class
public class B
inherits A
end class
Now if you define an object of B, it can definitely call the show function defined within A.
2. Polymorphism: The term signifies, that more than one form. How in case of OOPS, polymorphism can exist. Well, the support of this feature is because of OVERLOADING and OVERRIDING. The term overloading means, existence of more than one function in the same scope with same name. Well, just think, suppose we dont support overloading... just functions.. in that case, you have to define functions individually differently. So there may exist only one function say sum with some number of arguments. Now suppose you have defined a function sum as
public function sum(byval a as Integer, ByVal b as Integer) as Integer
sum=a+b
end Function
in this case, the function sum takes two arguments and returning the sum of both. Well, the condition is nice enough to sum up two numbers. Well, after defining this function suppose some requirement comes, where the function can sum up 3 numbers. Just now the problem begins. Now you need to name the function which you are to create differently. That means separate indentifier to separate functions.. You may think what will be the problem with this. Now suppose you have named a function which is working almost similarly but having different names and you need to remember all of their names. Here comes the benefit of Overloading where similar functions can be named identical but they should be having one common difference. The difference lies on their Argument List. Eg.
public overloads function sum(byval a as Integer,ByVal b as Integer)as Integer
Return a+b
end Function
public overloads Function sum(Byval a as Single,ByVal b as Single) as Single
Return a+b
End Function
Here the two functions having the same name but difference in arguments can stay on the same scope, i.e in a scope of a class. Mind that, overloading is a property of a class, so it would not be working if you write it in a standard module.
Another feature of Polymorphism is Overriding... In case of overriding, two functions are having exactly same signature ... but defined differently.. well, this make your all confusion, isnt it.. Well, how could be possible for a class to call the same two function with exactly the same signature...
Well the case is bit different. Well, the two function should stay on different classes, one in the base class, and another in the derived class... The base class will be overriding the derived class functions.. this is overriding....
Now look at the example
Class A
public overridable function abc()
msgbox ("Hii")
end Function
end class
Class B
Inherits A
Public overrides Function abc()
msgbox ("Hello")
end Function
End Class
So here when we call abc with the object of B, it will call the msgbox with hello, and when we create the object of a and call abc, it will call hi...
So we are modifying the definition of already defined function. isn't it beautiful...
I will continue my posts... later on...
Thanks for reading
As I have already told you, the first line just after the class name, you will be getting the inherits part. This inherits part making our task of getting a new form much easier. It would be worthy enough to get a well designed form just with a click of mouse. Isnt it. Its what we all know about the famous feature of any OOPS based language. In case of JAVA we have to derive from Frame class whereas here it is Form class. Both are the same thing.
OOPS concept:
1. Inheritence: Inheritence is the process of getting all the properties of the base class within the new class that you are deriving from. Well, its just a shortcut of getting everything pre-defined or created. So it just ensures reusability. Nothing else. Just once a class is defined, it can be inherited instantly to another class and can be used with their function whenever you require to use them. Only the exception if you define a class as NOTINHERITABLE, that class cannot be inherited. So hey hey.. until you are hard enough to give your code to other programmers, you can surely make your code Inheritable... Now lets look at the code below. public class A
public void show()
msgbox ("Hello") ' Messagebox function defined already within your scope...
end sub
end class
public class B
inherits A
end class
Now if you define an object of B, it can definitely call the show function defined within A.
2. Polymorphism: The term signifies, that more than one form. How in case of OOPS, polymorphism can exist. Well, the support of this feature is because of OVERLOADING and OVERRIDING. The term overloading means, existence of more than one function in the same scope with same name. Well, just think, suppose we dont support overloading... just functions.. in that case, you have to define functions individually differently. So there may exist only one function say sum with some number of arguments. Now suppose you have defined a function sum as
public function sum(byval a as Integer, ByVal b as Integer) as Integer
sum=a+b
end Function
in this case, the function sum takes two arguments and returning the sum of both. Well, the condition is nice enough to sum up two numbers. Well, after defining this function suppose some requirement comes, where the function can sum up 3 numbers. Just now the problem begins. Now you need to name the function which you are to create differently. That means separate indentifier to separate functions.. You may think what will be the problem with this. Now suppose you have named a function which is working almost similarly but having different names and you need to remember all of their names. Here comes the benefit of Overloading where similar functions can be named identical but they should be having one common difference. The difference lies on their Argument List. Eg.
public overloads function sum(byval a as Integer,ByVal b as Integer)as Integer
Return a+b
end Function
public overloads Function sum(Byval a as Single,ByVal b as Single) as Single
Return a+b
End Function
Here the two functions having the same name but difference in arguments can stay on the same scope, i.e in a scope of a class. Mind that, overloading is a property of a class, so it would not be working if you write it in a standard module.
Another feature of Polymorphism is Overriding... In case of overriding, two functions are having exactly same signature ... but defined differently.. well, this make your all confusion, isnt it.. Well, how could be possible for a class to call the same two function with exactly the same signature...
Well the case is bit different. Well, the two function should stay on different classes, one in the base class, and another in the derived class... The base class will be overriding the derived class functions.. this is overriding....
Now look at the example
Class A
public overridable function abc()
msgbox ("Hii")
end Function
end class
Class B
Inherits A
Public overrides Function abc()
msgbox ("Hello")
end Function
End Class
So here when we call abc with the object of B, it will call the msgbox with hello, and when we create the object of a and call abc, it will call hi...
So we are modifying the definition of already defined function. isn't it beautiful...
I will continue my posts... later on...
Thanks for reading
Bit related about Interfaces and Abstract classes.
So friends, until now, I think you have got the basic idea about the Object Oriented Programming paradigm. With changing atmosphere, it gets rather difficult to make a project worthwhile. So It needs a structured way to maintain the whole project. Every company before its very creation creates their own framework to make data access for their own products much more easier. The architecture what microsoft provides us is also structured. In talking about structure, one thing that comes first in our mind is Interface.
Lets discuss Interfaces a bit further...
Interface: An interface is a class that have only abstract methods and final variables. An abstract method is just a declaration of the signature without actual implementation of its body. Thus when creating an abstract function we dont need to create the body of the function. Its just the declaration of how a function looks line..
abstract Function sum(Byval x as Integer,ByVal y as Integer) as Integer
In the previous declaration, the function body is nothing, i.e, Its not defined yet. Just it would be defined or overridden to its derived classes.
If a class is having any function within it as abstract, the class must also be declared as abstract. Means, whenever we write any of the member function of a class as abstract, we are losing the propoerty of instantiating the object of that class. So the class will also be called as abstract.
abstract Class A
Function a()
End Class
Now Coming to Inheritence, as I mentioned in my earlier post, Inheritence is the process of making a class just derived from another class. Well, this property ensures re usability of code. Now In .NET environment, one class can have only one base, at most... So Multiple Inheritence is not supported in .NET environment. But this can be supported with the help of Interface.
Interfaces are pure abstract classes.. Means in an Interface there may not be any defination of any of its methods so that rather than inheriting from the class we use implementing from it. Just we need to override all of the functions defined within the interface in our class. This is the case of Multiple Inheritence where if you are implementing from interfaces, a single class can have multiple base classes.
Class A
Inherits BaseA 'Inherits can be only one
Implements Base IA,BaseIB 'Implements can be more than one
Public Function Afun() as string Implements BaseIA.Afun
end Function
Public Function Bfun() as string Implements BaseIB.Bfun
end Function
End class
So here a class A is having three base classes, One is which it is derived from and the others are which it is implementing.
Interface can point to the object of the class which it implementing it. means
Dim ba as BaseIA
ba=new A()
This is possible as if the base class can point to derived class objects.
So you will get everything like the base classes in case of implementing and can enjoy the flavour of Multiple Inheritence in VB.NET.....
Isn't it Cool....
Lets discuss Interfaces a bit further...
Interface: An interface is a class that have only abstract methods and final variables. An abstract method is just a declaration of the signature without actual implementation of its body. Thus when creating an abstract function we dont need to create the body of the function. Its just the declaration of how a function looks line..
abstract Function sum(Byval x as Integer,ByVal y as Integer) as Integer
In the previous declaration, the function body is nothing, i.e, Its not defined yet. Just it would be defined or overridden to its derived classes.
If a class is having any function within it as abstract, the class must also be declared as abstract. Means, whenever we write any of the member function of a class as abstract, we are losing the propoerty of instantiating the object of that class. So the class will also be called as abstract.
abstract Class A
Function a()
End Class
Now Coming to Inheritence, as I mentioned in my earlier post, Inheritence is the process of making a class just derived from another class. Well, this property ensures re usability of code. Now In .NET environment, one class can have only one base, at most... So Multiple Inheritence is not supported in .NET environment. But this can be supported with the help of Interface.
Interfaces are pure abstract classes.. Means in an Interface there may not be any defination of any of its methods so that rather than inheriting from the class we use implementing from it. Just we need to override all of the functions defined within the interface in our class. This is the case of Multiple Inheritence where if you are implementing from interfaces, a single class can have multiple base classes.
Class A
Inherits BaseA 'Inherits can be only one
Implements Base IA,BaseIB 'Implements can be more than one
Public Function Afun() as string Implements BaseIA.Afun
end Function
Public Function Bfun() as string Implements BaseIB.Bfun
end Function
End class
So here a class A is having three base classes, One is which it is derived from and the others are which it is implementing.
Interface can point to the object of the class which it implementing it. means
Dim ba as BaseIA
ba=new A()
This is possible as if the base class can point to derived class objects.
So you will get everything like the base classes in case of implementing and can enjoy the flavour of Multiple Inheritence in VB.NET.....
Isn't it Cool....
Subscribe to:
Posts (Atom)