Advertisement
7_2009-2012 Data Structures #238208

Oops in .NET

Hi! Friends This article show how "Object Oriented Programing" goes with .NET. Many people have bit problem with OOP's Concept in .net, So just take a look, then..... Ofcourse you are going to Vote. Bye.. have a fun

AI

AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Source Code
original-source
<html xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:w="urn:schemas-microsoft-com:office:word"
xmlns:st1="urn:schemas-microsoft-com:office:smarttags"
xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<meta name=ProgId content=Word.Document>
<meta name=Generator content="Microsoft Word 11">
<meta name=Originator content="Microsoft Word 11">
<link rel=File-List href="Opps_Dot_Net_files/filelist.xml">
<title>Oops with .net</title>
<o:SmartTagType namespaceuri="urn:schemas-microsoft-com:office:smarttags"
 name="City"/>
<o:SmartTagType namespaceuri="urn:schemas-microsoft-com:office:smarttags"
 name="place"/>
<!--[if gte mso 9]><xml>
 <o:DocumentProperties>
 <o:Author>Sandeep</o:Author>
 <o:Template>Normal</o:Template>
 <o:LastAuthor>Sandeep</o:LastAuthor>
 <o:Revision>2</o:Revision>
 <o:TotalTime>3</o:TotalTime>
 <o:Created>2007-02-19T17:50:00Z</o:Created>
 <o:LastSaved>2007-02-19T17:53:00Z</o:LastSaved>
 <o:Pages>1</o:Pages>
 <o:Words>2436</o:Words>
 <o:Characters>13886</o:Characters>
 <o:Company>Microsoft Corporation</o:Company>
 <o:Lines>115</o:Lines>
 <o:Paragraphs>32</o:Paragraphs>
 <o:CharactersWithSpaces>16290</o:CharactersWithSpaces>
 <o:Version>11.6360</o:Version>
 </o:DocumentProperties>
</xml><![endif]--><!--[if gte mso 9]><xml>
 <w:WordDocument>
 <w:SpellingState>Clean</w:SpellingState>
 <w:GrammarState>Clean</w:GrammarState>
 <w:ValidateAgainstSchemas/>
 <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
 <w:IgnoreMixedContent>false</w:IgnoreMixedContent>
 <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
 <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
 </w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
 <w:LatentStyles DefLockedState="false" LatentStyleCount="156">
 </w:LatentStyles>
</xml><![endif]--><!--[if !mso]><object
 classid="clsid:38481807-CA0E-42D2-BF39-B33AF135CC4D" id=ieooui></object>
<style>
st1\:*{behavior:url(#ieooui) }
</style>
<![endif]-->
<style>
<!--
 /* Font Definitions */
 @font-face
	{font-family:Verdana;
	panose-1:2 11 6 4 3 5 4 4 2 4;
	mso-font-charset:0;
	mso-generic-font-family:swiss;
	mso-font-pitch:variable;
	mso-font-signature:536871559 0 0 0 415 0;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
	{mso-style-parent:"";
	margin:0pt;
	margin-bottom:.0001pt;
	mso-pagination:widow-orphan;
	font-size:12.0pt;
	font-family:"Times New Roman";
	mso-fareast-font-family:"Times New Roman";}
h1
	{mso-margin-top-alt:auto;
	margin-right:0pt;
	mso-margin-bottom-alt:auto;
	margin-left:0pt;
	mso-pagination:widow-orphan;
	mso-outline-level:1;
	font-size:24.0pt;
	font-family:"Times New Roman";
	font-weight:bold;}
p
	{font-size:12.0pt;
	font-family:"Times New Roman";
	mso-fareast-font-family:"Times New Roman";}
p.style1, li.style1, div.style1
	{mso-style-name:style1;
	mso-margin-top-alt:auto;
	margin-right:0pt;
	mso-margin-bottom-alt:auto;
	margin-left:0pt;
	mso-pagination:widow-orphan;
	font-size:12.0pt;
	font-family:"Times New Roman";
	mso-fareast-font-family:"Times New Roman";
	color:#003399;
	font-weight:bold;}
p.style2, li.style2, div.style2
	{mso-style-name:style2;
	mso-margin-top-alt:auto;
	margin-right:0pt;
	mso-margin-bottom-alt:auto;
	margin-left:0pt;
	mso-pagination:widow-orphan;
	font-size:27.0pt;
	font-family:Verdana;
	mso-fareast-font-family:"Times New Roman";
	mso-bidi-font-family:"Times New Roman";}
p.style3, li.style3, div.style3
	{mso-style-name:style3;
	mso-margin-top-alt:auto;
	margin-right:0pt;
	mso-margin-bottom-alt:auto;
	margin-left:0pt;
	mso-pagination:widow-orphan;
	font-size:27.0pt;
	font-family:Verdana;
	mso-fareast-font-family:"Times New Roman";
	mso-bidi-font-family:"Times New Roman";
	color:#003399;
	font-weight:bold;}
p.style4, li.style4, div.style4
	{mso-style-name:style4;
	mso-margin-top-alt:auto;
	margin-right:0pt;
	mso-margin-bottom-alt:auto;
	margin-left:0pt;
	mso-pagination:widow-orphan;
	font-size:34.0pt;
	font-family:"Times New Roman";
	mso-fareast-font-family:"Times New Roman";}
p.style5, li.style5, div.style5
	{mso-style-name:style5;
	mso-margin-top-alt:auto;
	margin-right:0pt;
	mso-margin-bottom-alt:auto;
	margin-left:0pt;
	mso-pagination:widow-orphan;
	font-size:9.0pt;
	font-family:Verdana;
	mso-fareast-font-family:"Times New Roman";
	mso-bidi-font-family:"Times New Roman";}
p.style6, li.style6, div.style6
	{mso-style-name:style6;
	mso-margin-top-alt:auto;
	margin-right:0pt;
	mso-margin-bottom-alt:auto;
	margin-left:0pt;
	mso-pagination:widow-orphan;
	font-size:12.0pt;
	font-family:Verdana;
	mso-fareast-font-family:"Times New Roman";
	mso-bidi-font-family:"Times New Roman";
	font-weight:bold;}
p.style7, li.style7, div.style7
	{mso-style-name:style7;
	mso-margin-top-alt:auto;
	margin-right:0pt;
	mso-margin-bottom-alt:auto;
	margin-left:0pt;
	mso-pagination:widow-orphan;
	font-size:9.0pt;
	font-family:Arial;
	mso-fareast-font-family:"Times New Roman";
	color:#CC3399;
	font-weight:bold;}
p.style8, li.style8, div.style8
	{mso-style-name:style8;
	mso-margin-top-alt:auto;
	margin-right:0pt;
	mso-margin-bottom-alt:auto;
	margin-left:0pt;
	mso-pagination:widow-orphan;
	font-size:12.0pt;
	font-family:"Courier New";
	mso-fareast-font-family:"Times New Roman";
	color:#FF0033;}
p.style10, li.style10, div.style10
	{mso-style-name:style10;
	mso-margin-top-alt:auto;
	margin-right:0pt;
	mso-margin-bottom-alt:auto;
	margin-left:0pt;
	mso-pagination:widow-orphan;
	font-size:9.0pt;
	font-family:Verdana;
	mso-fareast-font-family:"Times New Roman";
	mso-bidi-font-family:"Times New Roman";
	font-weight:bold;}
p.style11, li.style11, div.style11
	{mso-style-name:style11;
	mso-margin-top-alt:auto;
	margin-right:0pt;
	mso-margin-bottom-alt:auto;
	margin-left:0pt;
	mso-pagination:widow-orphan;
	font-size:12.0pt;
	font-family:"Times New Roman";
	mso-fareast-font-family:"Times New Roman";
	color:#339966;}
p.style12, li.style12, div.style12
	{mso-style-name:style12;
	mso-margin-top-alt:auto;
	margin-right:0pt;
	mso-margin-bottom-alt:auto;
	margin-left:0pt;
	mso-pagination:widow-orphan;
	font-size:12.0pt;
	font-family:"Times New Roman";
	mso-fareast-font-family:"Times New Roman";
	color:#33CC00;}
p.style13, li.style13, div.style13
	{mso-style-name:style13;
	mso-margin-top-alt:auto;
	margin-right:0pt;
	mso-margin-bottom-alt:auto;
	margin-left:0pt;
	mso-pagination:widow-orphan;
	font-size:12.0pt;
	font-family:"Courier New";
	mso-fareast-font-family:"Times New Roman";
	color:#33CC00;}
span.style41
	{mso-style-name:style41;
	mso-ansi-font-size:34.0pt;
	mso-bidi-font-size:34.0pt;}
span.style61
	{mso-style-name:style61;
	font-family:Verdana;
	mso-ascii-font-family:Verdana;
	mso-hansi-font-family:Verdana;
	font-weight:bold;}
span.style51
	{mso-style-name:style51;
	mso-ansi-font-size:9.0pt;
	mso-bidi-font-size:9.0pt;
	font-family:Verdana;
	mso-ascii-font-family:Verdana;
	mso-hansi-font-family:Verdana;}
span.style101
	{mso-style-name:style101;
	mso-ansi-font-size:9.0pt;
	mso-bidi-font-size:9.0pt;
	font-family:Verdana;
	mso-ascii-font-family:Verdana;
	mso-hansi-font-family:Verdana;
	font-weight:bold;}
span.style81
	{mso-style-name:style81;
	font-family:"Courier New";
	mso-ascii-font-family:"Courier New";
	mso-hansi-font-family:"Courier New";
	mso-bidi-font-family:"Courier New";
	color:#FF0033;}
p.style8style11, li.style8style11, div.style8style11
	{mso-style-name:"style8 style11";
	font-size:12.0pt;
	font-family:"Times New Roman";
	mso-fareast-font-family:"Times New Roman";}
p.style8style12, li.style8style12, div.style8style12
	{mso-style-name:"style8 style12";
	font-size:12.0pt;
	font-family:"Times New Roman";
	mso-fareast-font-family:"Times New Roman";}
span.SpellE
	{mso-style-name:"";
	mso-spl-e:yes;}
span.GramE
	{mso-style-name:"";
	mso-gram-e:yes;}
@page Section1
	{size:612.0pt 792.0pt;
	margin:72.0pt 90.0pt 72.0pt 90.0pt;
	mso-header-margin:36.0pt;
	mso-footer-margin:36.0pt;
	mso-paper-source:0;}
div.Section1
	{page:Section1;}
-->
</style>
<!--[if gte mso 10]>
<style>
 /* Style Definitions */
 table.MsoNormalTable
	{mso-style-name:"Table Normal";
	mso-tstyle-rowband-size:0;
	mso-tstyle-colband-size:0;
	mso-style-noshow:yes;
	mso-style-parent:"";
	mso-padding-alt:0pt 5.4pt 0pt 5.4pt;
	mso-para-margin:0pt;
	mso-para-margin-bottom:.0001pt;
	mso-pagination:widow-orphan;
	font-size:10.0pt;
	font-family:"Times New Roman";
	mso-ansi-language:#0400;
	mso-fareast-language:#0400;
	mso-bidi-language:#0400;}
</style>
<![endif]--><!--[if gte mso 9]><xml>
 <o:shapedefaults v:ext="edit" spidmax="2050"/>
</xml><![endif]--><!--[if gte mso 9]><xml>
 <o:shapelayout v:ext="edit">
 <o:idmap v:ext="edit" data="1"/>
 </o:shapelayout></xml><![endif]-->
</head>

<div class=Section1>
<h1 align=center style='text-align:center'>OOP's - Object Oriented Programming</h1>
<h1 align=center style='text-align:center'><span style='font-size:27.0pt;
font-family:Verdana;color:#003399'>With </span><span class=style41><span
style='font-size:34.0pt;font-family:Verdana;color:#003399'>.NET </span></span><span
style='font-size:27.0pt;font-family:Verdana;color:#003399'><o:p></o:p></span></h1>
<p class=style5>Everything in the world is an object. The type of the object
may vary. In OOPS, we get the power to create objects of our own, as &amp; when
required. </p>
<p><span class=style61>Class </span>- <span class=style51><span
style='font-size:9.0pt'>A class is an organized store-house in object-oriented
programming that gives coherent functional abilities to a group of related
code. It is the definition of an object, made up of software code. Using
classes, we may wrap data and behavior together (</span></span><strong><span
style='font-size:9.0pt;font-family:Verdana'>Encapsulation</span></strong><span
class=style51><span style='font-size:9.0pt'>). We may define classes in terms
of classes (</span></span><strong><span style='font-size:9.0pt;font-family:
Verdana'>Inheritance</span></strong><span class=style51><span style='font-size:
9.0pt'>). We can also override the behavior of a class using an alternate
behavior (</span></span><strong><span style='font-size:9.0pt;font-family:Verdana'>Polymorphism</span></strong><span
class=style51><span style='font-size:9.0pt'>)</span></span>. </p>
<p class=style7 align=center style='text-align:center'>EMPLOYEE</p>
<p class=style7 align=center style='text-align:center'>PERMANENT
-------------------- WAGE WORKER </p>
<p class=style5>Using inheritance, we may assign different traits to different
classes. Yet, the child classes will inherit some common traits from the base
class. <span class=GramE>As in the figure above, the classes for
&quot;Permanent&quot; and &quot;Wage Worker&quot; will inherit some common
traits from the class of &quot;Employee&quot;.</span></p>
<p><span class=style51><span style='font-size:9.0pt'>A class may contain class
members like fields, properties, events &amp; methods with different types of
access modifiers like private, public, <span class=GramE>protected</span> or
friend, to process the way they are accessed. In VB.NET, a class may be
declared as below.</span></span></p>
<p class=style8>Public Class <span class=SpellE>SampleClass</span></BR> </p>
<p class=style8>&nbsp; &nbsp; 'define class members<o:p></o:p></p>
<p class=style8></BR>End Class </p>
<p><span class=style101><span style='font-size:9.0pt'>Key Concepts of .NET</span></span>
<span class=style51><span style='font-size:9.0pt'>- To work with classes and
modules, the key concepts to know are definition, access, inheritance,
constructors, destructors, delegates, abstract classes &amp; interfaces.</span></span></p>
<p><span class=style101><span style='font-size:9.0pt'>Class members</span></span>
<span class=style51><span style='font-size:9.0pt'>- The different types of
entities in a class, like fields, properties, events &amp; methods. </span></span></p>
<p><span class=style101><span style='font-size:9.0pt'>Object</span></span> - <span
class=style51><span style='font-size:9.0pt'>An object is an instance of a
class. This instance may be used to access the members of the class. It is
pretty easy to define an object. See sample code below.</span></span></p>
<p class=style8>Dim objSampleObject as SampleClass </p>
<p>&nbsp; </p>
<p><span class=style101><span style='font-size:9.0pt'>Structure</span></span> -
<span class=style51><span style='font-size:9.0pt'>It is a bit similar to a
class. Semantically, structures are known as value types, while classes as
reference types. We don't instantiate an object using the </span></span><span
class=style81>New</span><span class=style51><span style='font-size:9.0pt'>
keyword while working with a structure. We can not inherit from a structure.</span></span>
</p>
<p class=style8>Public Structure Student </p>
<p class=style8>Public RollNo as Integer </p>
<p class=style8>Public Name as String </p>
<p class=style8>End Structure </p>
<p>&nbsp; </p>
<p class=style8>Dim objStud as Student </p>
<p class=style8>&nbsp; objStud.RollNo=31 </p>
<p class=style8>&nbsp; <span class=SpellE>objStud.Name</span>=&quot;<st1:City
w:st="on"><st1:place w:st="on">Sandy</st1:place></st1:City>&quot; </p>
<p>&nbsp; </p>
<p class=style5>Here, note that the object objStud is not exactly an instance,
it is a simple object (object of a structure) that is used to access the
members of this structure. It would have behaved differently had it been an
object of a class, as it would have invoked the constructor associated with the
class. </p>
<p class=style8>Public Class <span class=SpellE>ClassCalc</span> </p>
<p class=style8>Public Function <span class=SpellE><span class=GramE>FnAdd</span></span><span
class=GramE>(</span><span class=SpellE>ByVal</span> <span class=SpellE>dblA</span>
as double, <span class=SpellE>ByVal</span> <span class=SpellE>dblB</span> as
double) as Double </p>
<p class=style8><span class=SpellE>FnAdd</span> = <span class=SpellE>dblA</span>
+ <span class=SpellE>dblB</span> </p>
<p class=style8>End Function </p>
<p class=style8>End Class </p>
<p>Now, <span class=GramE>lets</span> make use of the method <span
class=SpellE>FnAdd</span> defined in the class above. To use it, first create
an object of this class, say <span class=SpellE>objX</span>. Using this object,
we can invoke the methods of this class. See code below.</p>
<p>&nbsp; </p>
<p class=style8>Dim <span class=SpellE>objX</span> as <span class=SpellE>ClassCalc</span>
</p>
<p class=style8>Dim <span class=SpellE>dblResult</span> as Double </p>
<p class=style8><span class=SpellE><span class=GramE>dblResult</span></span> = <span
class=SpellE>objX.FnAdd</span>(4.56,2.35) </p>
<p>&nbsp; </p>
<p><span class=style101><span style='font-size:9.0pt'>Property</span></span> -<span
class=style51><span style='font-size:9.0pt'> A property is a thing that
describes the features of an object. A property is a piece of data contained
within a class that has an exposed interface for reading/writing. Looking at
that definition, you might think you could declare a public variable in a class
and call it a property. While this assumption is somewhat valid, the true
technical term for a public variable in a class is a field. The key difference
between a field and a property is in the inclusion of an interface.</span></span>
</p>
<p class=style5>We make use of <span class=style81>Get</span> and <span
class=style81>Set</span> keywords while working with properties. We prefix the
variables used within this code block with an underscore. Value is a <span
class=GramE>keyword, that</span> holds the value which is being retrieved or
set. </p>
<p>&nbsp; </p>
<p class=style8>Private _Color As String </p>
<p class=style8>Public Property <span class=GramE>Color()</span> </p>
<p class=style8>Get </p>
<p class=style8>Return _Color </p>
<p class=style8>End Get </p>
<p class=style8><span class=GramE>Set(</span><span class=SpellE>ByVal</span>
Value) </p>
<p class=style8>_Color = Value </p>
<p class=style8>End Set </p>
<p class=style8>End Property </p>
<p><span class=style101><span style='font-size:9.0pt'>Event</span></span> - <span
class=style51><span style='font-size:9.0pt'>An action that an object does. When
something happens, we say an event has happened. For example, when a button is
clicked, we say it is the <span class=GramE>click(</span> ) event. When a mouse
hovers on an image, we say the <span class=SpellE><span class=GramE>mouseover</span></span><span
class=GramE>(</span> ) event has taken place.</span></span> </p>
<p><span class=style101><span style='font-size:9.0pt'>Access Modifiers</span></span>
- <span class=style51><span style='font-size:9.0pt'>Keywords used to vary the
way members of a class are used. Following are different types.</span></span></p>
<p><span class=style101><span style='font-size:9.0pt'>1) Public</span></span> -
<span class=style51><span style='font-size:9.0pt'>These classes can be used
anywhere in the code.</span></span> </p>
<p class=style5>There are no restrictions. </p>
<p class=style5><strong><i><span style='font-family:Verdana'>Available only to
code outside our class </span></i></strong></p>
<p><span class=style101><span style='font-size:9.0pt'>2) Private </span></span>-
<span class=style51><span style='font-size:9.0pt'>These classes are accessible
only within their declaration contexts. This includes nested procedures. When a
variable is declared Public inside a Private class, it is accessible only from
inside that class.</span></span> </p>
<p class=style10><em><span style='font-family:Verdana'>Available only to code
inside our class </span></em></p>
<p><span class=style101><span style='font-size:9.0pt'>3) Protected</span></span>
- <span class=style51><span style='font-size:9.0pt'>These classes extend the
accessibility of their members to their child classes (means, to the classes
that derive from them). They extend their members to both themselves &amp;
their child classes. </span></span></p>
<p class=style10><em><span style='font-family:Verdana'>Available only to
classes that inherit from our class </span></em></p>
<p><span class=style101><span style='font-size:9.0pt'>4) Friend</span></span> -
<span class=style51><span style='font-size:9.0pt'>Friend access means that
elements are accessible only within the program. Friend is the default access modifier
for any class that does not have a modifier.</span></span> </p>
<p class=style10><em><span style='font-family:Verdana'>Available only to code
within our project/component </span></em></p>
<p><span class=style101><span style='font-size:9.0pt'>5) Protected Friend</span></span>
- <span class=style51><span style='font-size:9.0pt'>Available only to classes
that inherit from our class (in any project) or to code within our
project/component. This is a combination of Protected and Friend.</span></span>
</p>
<p>&nbsp; </p>
<p><span class=style101><span style='font-size:9.0pt'>Default </span></span>- <span
class=style51><span style='font-size:9.0pt'>A Default property is a single
property of a class that can be set as the default. This allows developers that
use your class to work more easily with your default property because they do
not need to make a direct reference to the property. Default properties cannot
be initialized as </span></span><span class=style81>Shared</span><span
class=style51><span style='font-size:9.0pt'> or </span></span><span
class=style81>Private</span><span class=style51><span style='font-size:9.0pt'>
and all must be accepted at least on argument or parameter. Default properties
do not promote good code readability, so use this option sparingly.</span></span>
</p>
<p><span class=style101><span style='font-size:9.0pt'>Overloads</span></span> -
<span class=style51><span style='font-size:9.0pt'>The Overloads property allows
a function to be described using deferent combinations of parameters. Each
combination is considered a signature, thereby uniquely defining an instance of
the method being defined. You can define a function with multiple signatures
without using the keyword Overloads, but if you use the Overloads keyword in
one, you must use it in all of the function's Overloaded signatures.</span></span>
</p>
<p><span class=style101><span style='font-size:9.0pt'>Shared</span></span> -<span
class=style51><span style='font-size:9.0pt'>The Shared keyword is used in an
inherited or base class to define a property or method as being shared among
all instances of a given class. If multiple instances of a class with shared
properties or methods are loaded, the shared properties or methods will provide
the same data across each instance of the class. When one class alters the
value for a shared property, all instances of that class will reflect the
change. Shared properties of all instances of the class point to the same
memory location. </span></span></p>
<p><span class=SpellE><span class=style101><span style='font-size:9.0pt'>Overridable</span></span></span>
-<span class=style51><span style='font-size:9.0pt'>The <span class=SpellE>Overridable</span>
keyword is used when defining a property or method of an inherited class, as <span
class=SpellE>overridable</span> by the inheriting class.</span></span> </p>
<p><span class=SpellE><span class=style101><span style='font-size:9.0pt'>Overides</span></span></span>
- <span class=style51><span style='font-size:9.0pt'>The Overrides keyword
allows the inheriting class to disregard the property or method of the
inherited class and implements <span class=SpellE>ts</span> own code.</span></span>
</p>
<p><span class=SpellE><span class=style101><span style='font-size:9.0pt'>NotOverridable</span></span></span>
- <span class=style51><span style='font-size:9.0pt'>The <span class=SpellE>NotOverridable</span>
keyword explicitly declares a property or method as not <span class=SpellE>overridable</span>
by an inheriting class, and all properties are &quot;not <span class=SpellE>overridable</span>&quot;
by default. The only real advantage to using this keyword is to make your code
more readable.</span></span> </p>
<p><span class=SpellE><span class=style101><span style='font-size:9.0pt'>MustOverride</span></span></span>
- <span class=style51><span style='font-size:9.0pt'>The <span class=SpellE>MustOverride</span>
keyword forces the inheriting class to implement its own code for the property
or method.</span></span> </p>
<p><span class=style101><span style='font-size:9.0pt'>Shadows</span></span> - <span
class=style51><span style='font-size:9.0pt'>The Shadows keyword will
effectively hide all of the other methods in the <span class=SpellE>baseclass</span>.
It is like forcefully getting rid of the overloading that has been done on the
methods of the base class. The Shadows keyword works like the Overloads keyword
except that with shadows we do not have to follow rules such as implementing
the same signature. The Shadows keyword does not require the consent (override
ability) of the inherited class to replace the property or method's
implementation code. A method does not have to be defined as <span
class=SpellE>overridable</span> for the Shadows keyword to work. Read the
example..</span></span>. </p>
<p class=style8style11>'This is the Base Class </p>
<p class=style8>Public Class Parent </p>
<p class=style8>Public Sub <span class=SpellE><span class=GramE>MyProc</span></span><span
class=GramE>(</span><span class=SpellE>ByVal</span> num As Integer) </p>
<p class=style8><span class=SpellE><span class=GramE>MsgBox</span></span><span
class=GramE>(</span>&quot;Number in Parent is &quot; &amp; num) </p>
<p class=style8>End Sub </p>
<p>&nbsp; </p>
<p class=style8>Public Sub <span class=SpellE><span class=GramE>MyProc</span></span><span
class=GramE>(</span><span class=SpellE>ByVal</span> <span class=SpellE>st</span>
As String) </p>
<p class=style8><span class=SpellE><span class=GramE>MsgBox</span></span><span
class=GramE>(</span>&quot;String in Parent is &quot; &amp; <span class=SpellE>st</span>)
</p>
<p class=style8>End Sub </p>
<p class=style8>End Class </p>
<p>&nbsp; </p>
<p class=style8style12>'This is the Child Class </p>
<p class=style8>Public Class Child </p>
<p class=style8>Inherits Parent </p>
<p class=style8>Overloads Sub <span class=SpellE><span class=GramE>MyProc</span></span><span
class=GramE>(</span><span class=SpellE>ByVal</span> num As Integer) </p>
<p class=style13>'<span class=GramE>overloads</span> the method with the same
parameter list </p>
<p class=style8><span class=SpellE><span class=GramE>MsgBox</span></span><span
class=GramE>(</span>&quot;Number in Child is &quot; &amp; num) </p>
<p class=style8>End Sub </p>
<p>&nbsp; </p>
<p class=style8>Overloads Sub <span class=SpellE><span class=GramE>MyProc</span></span><span
class=GramE>(</span><span class=SpellE>ByVal</span> <span class=SpellE>ch</span>
As Char) </p>
<p class=style13><span class=GramE>' overloads</span> the method </p>
<p class=style8><span class=SpellE><span class=GramE>MsgBox</span></span><span
class=GramE>(</span>&quot;Character in Child is &quot; &amp; <span
class=SpellE>ch</span>) </p>
<p class=style8>End Sub </p>
<p class=style8>End Class </p>
<p class=style10>When we execute the following code... </p>
<p class=style8>Dim c As New <span class=GramE>Child()</span> </p>
<p class=style13><span class=GramE>' prints</span> out &quot;String in Parent
is Hello <span class=SpellE>Wazzup</span>!&quot; </p>
<p class=style8><span class=SpellE><span class=GramE>c.MyProc</span></span><span
class=GramE>(</span>&quot;Hello <span class=SpellE>Wazzup</span>!&quot;) </p>
<p class=style13><span class=GramE>' prints</span> out &quot;Number in Child is
12&quot; </p>
<p class=style8><span class=SpellE><span class=GramE>c.MyProc</span></span><span
class=GramE>(</span>12) </p>
<p class=style13><span class=GramE>' prints</span> out &quot;Character in <span
class=SpellE>DerivedClass</span> is B&quot; </p>
<p class=style8><span class=SpellE><span class=GramE>c.MyProc</span></span><span
class=GramE>(</span><span class=SpellE>Chr</span>(66)) </p>
<p class=style10>When we use Shadows keyword... </p>
<p class=style8>Public Class ChildNumber2 </p>
<p class=style8>Inherits Parent </p>
<p class=style8>Shadows Sub <span class=SpellE><span class=GramE>MyProc</span></span><span
class=GramE>(</span><span class=SpellE>ByVal</span> num As Integer) </p>
<p class=style13><span class=GramE>' hides</span> all the different argument
list </p>
<p class=style8><span class=SpellE><span class=GramE>MsgBox</span></span><span
class=GramE>(</span>&quot;Number in ChildNumber2 is &quot; &amp; num) </p>
<p class=style8>End Sub </p>
<p class=style8>End Class </p>
<p class=style8>Dim c2 As New <span class=GramE>DerivedClass2()</span> </p>
<p class=style8><span class=GramE>c2.MyProc(</span>7) 'only one method is
exposed, rest of the </p>
<p class=style13>'<span class=GramE>methods</span> are hidden </p>
<p><span class=style101><span style='font-size:9.0pt'>Constructor</span></span>
- <span class=style51><span style='font-size:9.0pt'>When a class instance is
created in our code, a special method of that class, called the constructor, is
called. Similarly, when the class is destroyed, the destructor method is
called. These are general terms and usually not the actual member names in most
object-oriented languages. It is initialized using the keyword New, and is
destroyed using the keyword Finalize. In .NET, we tend to forget using Finalize
as the <span class=GramE>instances(</span>means the object) are automatically
destroyed by the Garbage Collector, when the object is not in use by he </span></span><strong><span
style='font-size:9.0pt;font-family:Verdana'>CLR</span></strong><span
class=style51><span style='font-size:9.0pt'>(Common Language Runtime). </span></span></p>
<p class=style8>Dim <span class=SpellE>objSampleObject</span> as New <span
class=SpellE>SampleClass</span> </p>
<p class=style13><span class=GramE>' write</span> the code here... </p>
<p class=style8><span class=SpellE>objsampleobject.Finalize</span> </p>
<p class=style5>We can add parameters to the constructors. This wasn&#8217;t
allowed in VB6. We can overload the <span class=GramE>constructors,</span> change
the order of parameters, data types of parameters which ultimately change the
way the constructor works whenever an instance of that class is invoked. </p>
<p class=style5>Also note that a constructor can have any access modifier. If
no argument is added in a constructor, VB.NET adds a no-argument constructor
during compile time. It adds the <span class=style81>Public Sub <span
class=GramE>New(</span> )</span> with the class declared, if no argument is
passed in the constructor. The following code is added... </p>
<p class=style8>Public Class <span class=SpellE>ClassA</span> </p>
<p class=style8>Public Sub <span class=GramE>New(</span> ) </p>
<p class=style8>End Sub </p>
<p class=style5>However, when the constructor is added with parameters, the
following code is generated... </p>
<p class=style8>Public Class <span class=SpellE>ClassA</span> </p>
<p class=style8>Public Sub <span class=GramE>New(</span><span class=SpellE>ByVal</span>
<span class=SpellE>SomeString</span> as String ) </p>
<p class=style8>End Sub </p>
<p>&nbsp; </p>
<p class=style5>When a child class' object is declared, the child class
constructor &amp; its parent class constructor, both are invoked. Read example
below for more clarity... </p>
<p class=style8>Public Class Books </p>
<p class=style8>Public Sub <span class=GramE>New()</span> </p>
<p class=style8><span class=SpellE><span class=GramE>System.Console.WriteLine</span></span><span
class=GramE>(</span>&quot;Book's constructor.&quot;) </p>
<p class=style8>End Sub </p>
<p>&nbsp; </p>
<p class=style8>Public Sub <span class=SpellE><span class=GramE>myProc</span></span><span
class=GramE>()</span> </p>
<p class=style8><span class=SpellE><span class=GramE>System.Console.WriteLine</span></span><span
class=GramE>(</span>&quot;This is a book.&quot;) </p>
<p class=style8>End Sub </p>
<p class=style8>End Class </p>
<p>&nbsp; </p>
<p class=style8>Public Class <span class=GramE>Authors :</span> Inherits Books </p>
<p class=style8>Public Sub <span class=GramE>New()</span> </p>
<p class=style8><span class=SpellE><span class=GramE>System.Console.WriteLine</span></span><span
class=GramE>(</span>&quot;Author's constructor.&quot;) </p>
<p class=style8>End Sub </p>
<p class=style8>End Class </p>
<p class=style5>When the Authors class' constructor is invoked, like in the
following code, the Books class' no-argument constructor is also called. </p>
<p class=style8>Dim author As Authors </p>
<p class=style8><span class=GramE>author</span> = New Authors() </p>
<p class=style5>The result on the console will be... </p>
<p class=style5><span class=GramE>Book's constructor.</span> </p>
<p class=style5><span class=GramE>Author's constructor.</span> </p>
<p class=style5>If the base class doesn&#8217;t have a no-argument constructor,
then it would result in a compiler error. Hence, we need to use the <span
class=SpellE>MyBase</span> keyword with the constructor. Our child class will
look like this... </p>
<p class=style8>Public Class <span class=GramE>Authors :</span> Inherits Books </p>
<p class=style8>Public Sub <span class=GramE>New(</span><span class=SpellE>ByVal</span>
<span class=SpellE>SomeString</span> As String) </p>
<p class=style8><span class=SpellE><span class=GramE>MyBase.New</span></span><span
class=GramE>(</span><span class=SpellE>SomeString</span>) </p>
<p class=style8><span class=SpellE><span class=GramE>System.Console.WriteLine</span></span><span
class=GramE>(</span>&quot;<span class=SpellE>Authors's</span>
constructor.&quot;) </p>
<p class=style8>End Sub </p>
<p><span class=style81>End Class</span> </p>
<p class=style5>If a class is not inheriting from any base class, then it will
call the base class constructor of <span class=SpellE>System.Object</span> if
we are using <span class=SpellE><span class=GramE>MyBase.New</span></span><span
class=GramE>(</span> ). Summarizing constructors, whenever we initiate a
constructor, the following things happen... </p>
<p class=style5>Base class constructor is invoked. </p>
<p class=style5>Class level variables are initialized. </p>
<p class=style5>Code in the class constructor gets executed. </p>
<p class=style5>If the argument name passed in the <span class=GramE>constructor,</span>
is same as the variable name used in the constructor, we use the Me keyword to
refer to the constructor variable. For example if the variable name is <span
class=SpellE>SomeString</span>, and the parameter passed is also <span
class=SpellE>SomeString</span>, then the variable is referred as <span
class=SpellE>Me.SomeString</span>. </p>
<p>&nbsp; </p>
<p><span class=style101><span style='font-size:9.0pt'>Abstract Class</span></span>
-<span class=style51><span style='font-size:9.0pt'> They are classes that
cannot be instantiated. We cannot create an object from such a class for use in
our program. We can use an abstract class as a base class, creating new classes
that will inherit from it. Creating an abstract class with a certain minimum
required level of functionality gives us a defined starting point from which we
can derive non-abstract classes.</span></span> </p>
<p class=style5>An abstract class may contain abstract methods &amp;
non-abstract methods. When a class is derived from an abstract class, the
derived class must implement all the abstract methods declared in the base
class. We may use accessibility modifiers in an abstract class (unlike in
Interfaces). </p>
<p class=style5>An abstract class can inherit from a non-abstract class. In
C++, this concept is known as <strong><span style='font-family:Verdana'>pure
virtual method</span></strong>.</p>
<p>&nbsp; </p>
<p><span class=style101><span style='font-size:9.0pt'>Interface</span></span> -
<span class=GramE><span class=style51><span style='font-size:9.0pt'>its</span></span></span><span
class=style51><span style='font-size:9.0pt'> a kind of class, that has only
methods, do not have code, just the definition of the methods. Also, the
interface can't be instantiated. <span class=GramE>Its</span> an abstract class
with public abstract methods, all of which must be implemented in the inherited
classes. All methods in an interface are <span class=GramE>public,</span> no
other access modifier is used. It is public by default. </span></span></p>
<p>&nbsp; </p>
<p class=style5>Classes can contain code, but interface don&#8217;t. However,
classes that implement an interface do contain code. Keep in mind that there
are no instances of interfaces in VB .NET. Every instance is a type that
implements an interface, but is itself not an instance of the interface. Also
note, in an interface, all methods must be abstract (which is not necessary in
an abstract class). </p>
<p class=style13>'VB .NET Interface </p>
<p class=style8>Public Interface <span class=SpellE>ISalary</span> </p>
<p class=style8>Sub <span class=SpellE><span class=GramE>CreditSalary</span></span><span
class=GramE>(</span><span class=SpellE>ByVal</span> Amount As Decimal) </p>
<p class=style8><span class=SpellE>ReadOnly</span> Property <span class=GramE>Incentive(</span>)
As Decimal </p>
<p class=style8><span class=SpellE>ReadOnly</span> Property <span class=GramE>Attendance(</span>)
As Integer </p>
<p class=style8>End Interface </p>
<p class=style5>To use members of an interface, we make use of the implements
keyword. </p>
<p class=style8>Public Class Employee </p>
<p class=style8>Implements <span class=SpellE>ISalary</span> </p>
<p class=style8>Public Function <span class=GramE>Salary(</span>) As Decimal
Implements <span class=SpellE>ISalary.CreditSalary</span>() </p>
<p class=style13>'<span class=GramE>code</span> here ... </p>
<p class=style8>End Function </p>
<p class=style8>End Class </p>
<p><span class=SpellE><span class=style101><span style='font-size:9.0pt'>Serializable</span></span></span>
-<span class=style51><span style='font-size:9.0pt'> This is a class attribute.
When we use this attribute with a class, an instance of this class can be taken
in whatever state it is, and write it to a disk. The class can then be desterilized,
and the class will act as if it is simply stored in the memory.</span></span> </p>
<p><span class=style101><span style='font-size:9.0pt'>Boxing &amp; <span
class=SpellE>Unboxing</span></span></span> - <span class=style51><span
style='font-size:9.0pt'>Value Types are stored on the stack and Reference types
are stored on the heap. The conversion of value type to reference type is known
as Boxing. Converting reference type back to value type </span></span>is known
as <span class=SpellE>Unboxing</span>. </p>
<p><span class=style101><span style='font-size:9.0pt'>Value Types</span></span>
- <span class=style51><span style='font-size:9.0pt'>Value types are primitive
types that are mapped directly to the FCL. Like Int32 maps to System.Int32,
double maps to <span class=SpellE>System.double</span>.</span></span> </p>
<p class=style5>All value types are stored on stack and all the value types are
derived from <span class=SpellE>System.ValueType</span>. All structures and
enumerated types that are derived from <span class=SpellE>System.ValueType</span>
are created on stack, hence known as <span class=SpellE>ValueType</span>. </p>
<p><span class=style101><span style='font-size:9.0pt'>Reference Types</span></span>
-<span class=style51><span style='font-size:9.0pt'> Reference Types are
different from value types in such a way that memory is allocated to them from
the heap. All the classes are of reference type. C# new operator returns the
memory address of the object. </span></span></p>
<p><span class=style101><span style='font-size:9.0pt'>Partial Class</span></span>
- <span class=style51><span style='font-size:9.0pt'>This concept has been
introduced in .NET framework 2.0. They give you the ability to split a single
class into more than one source code (.<span class=SpellE>cs</span> or .<span
class=SpellE>vb</span>) file. Here's what a partial class looks like when <span
class=GramE>it's</span> split over two files... </span></span></p>
<p class=style13>// <span class=GramE>Stored</span> in file MyClass1.cs </p>
<p class=style8><span class=GramE>public</span> partial class <span
class=SpellE>MyClass</span> </p>
<p class=style8>{ </p>
<p class=style8><span class=GramE>public</span> <span class=SpellE>MethodA</span>()
</p>
<p class=style8>{...} </p>
<p class=style8>} </p>
<p>&nbsp; </p>
<p class=style13>// <span class=GramE>Stored</span> in file MyClass2.cs </p>
<p class=style8><span class=GramE>public</span> partial class <span
class=SpellE>MyClass</span> </p>
<p class=style8>{ </p>
<p class=style8><span class=GramE>public</span> <span class=SpellE>MethodB</span>()
</p>
<p class=style8>{...} </p>
<p class=style8>} </p>
<p class=style5>When you build the application, Visual Studio .NET tracks down
each piece of <span class=SpellE>MyClass</span> and assembles it into a
complete, compiled class with two methods, <span class=SpellE>MethodA</span>()
and <span class=SpellE>MethodB</span>(). </p>
<p class=style5>Partial classes don't offer much in the way of solving
programming problems, but they can be useful if you have extremely large,
unwieldy classes. (Of course, this might be a sign that you haven't properly
factored your problem, in which case you should really break your class down
into separate classes.) The real purpose of partial classes in .NET is to hide
automatically generated designer code. </p>
</div>

</html>
Original Comments (3)
Recovered from Wayback Machine