Академический Документы
Профессиональный Документы
Культура Документы
Abstraction
It allows complex real world to be represented in simplified manner.Example color is
abstracted to RGB.By just making the combination of these three colors we can
achieve
any color in world.Its a model of real world or concept.
Encapsulation
The process of hiding all the internal details of an object from the outside world.
Communication using messages
When application wants to achieve certain task it can only be done using
combination of
objects.A single object can not do all the task.Example if we want to make order
processing
form. We will use Customer object , Order object , Product object and Payment
object to
achieve this functionality.In short these objects should communicate with each
other.This
is achieved when objects send messages to each other.
Object lifetime
All objects have life time.Objects are created , initialized , necessary functionalities
are
done and later the object is destroyed.Every object have there own state and
identity ,
Inheritance
Hierarchy is used to define more specialized classes based on a preexisting
generalized
class.Example we have VEHICLE class and we can inherit this class make more
specialized
class like CAR, which will add new attributes and use some existing qualities of the
parent class.Its shows more of a parent-child relationship .This kind of hierarchy is
called
inheritance.
Polymorphism
When inheritance is used to extend a generalized class to a more specialized class,it
includes
End Class
Above is the source which parses only @ of strData variable.
v Abstract class is designed to act as a base class (to be inherited by other classes).
Abstract class is a design concept in program development and provides a
base upon which other classes are built.
v Abstract classes are similar to interfaces. After declaring an abstract class, it
objDelegateAddString.Invoke()
End Sub
End Class
In the above there is a method called AddString() which adds a string to a
listbox.You
can also see a delegate declared as :Public Delegate Sub DelegateAddString()
This delegate signature is compatible with the AddString method.When i mean
compatibility that means that there return types and passing parameter types are
same.Later
in command click of the button object of the Delegate is created and the method
pointer
is received from AddressOf keyword.Then by using the Invoke method the
method
is invoked.
Figure :- 6.4 Delegate in Action
(B) What are events ?
As compares to delegates events works with source and listener methodology . So
listeners
who are interested in receiving some events they subscribe to the source.Once this
subscription is done the source raises events to all of its listener when needed.One
source
can have multiple listeners.
In example sample given below class ClsWithEvents is a event source class ,
which has
a event EventAddString().Now the listeners who are interested in receiving this
events
they can subscribe to this event.In class FrmWithEvents you can see the handles
clause
Inherits ClsParent
Public Shadows x As String
End Class
c.XyzCallback = null
This will reset all your delegates to nothing and you have to keep figuring where the
error
is.
(B) If we inherit a class do the private variables also get
inherited ?
Yes the variables are inherited but can not be accessed directly by the class
interface.
(B) What are different accessibility levels defined in .NET ?
Following are the five levels of access modifiers :v Private : Only members of class have access.
v Protected :-All members in current class and in derived classes can access the
variables.
v Friend (internal in C#) :- Only members in current project have access to the
elements.
v Protected friend (protected internal in C#) :- All members in current project
and all members in derived class can access the variables.
v Public :- All members have access in all classes and projects.
(I) Can you prevent a class from overriding ?
If you define a class as Sealed in C# and NotInheritable in VB.NET you can
inherit
the class any further.
(I) Whats the use of MustInherit keyword in VB.NET ?
If you want to create a abstract class in VB.NET its done by using MustInherit
keyword.This acts only as base type and can not be inherited any further.You can
not
create a object of a class which is marked as MustInherit.
Following are the similarities between classes and structures :v Both can have constructors, methods, properties, fields, constants,
enumerations, events, and event handlers.
v Structures and classes can implement interface.
v Both of them can have constructors without parameter and with parameter.
v Both can have delegates and events.
(A) Whats the difference between Class and structures ?
Following are the key differences between them :v Structure are value types and classes are reference types.So structures use
stack and classes use heap.
v Structures members can not be declared as protected , but class members can
be.You can not do inheritance in structures.
v Structures do not require constructors while classes require.
v Objects created from classes are terminated using Garbage collector.Structures
are not destroyed using GC.
(B) What does virtual keyword mean ?
That method and property can be overridden.
(B) What are shared (VB.NET)/Static(C#) variables?
Static/Shared classes are used when a class provides functionality which is not
specific to
any instance.In short if you want a object to be shared between multiple instances
you
will use a static/Shared class.
Following are features of Static/Shared classes :v They can not be instantiated.By default a object is created on the first method
call to that object.
Array whose size can increase and decrease dynamically.Arraylist can hold item of
different
types.As Arraylist can increase and decrease size dynamically you do not have to
use the
REDIM keyword.You can access any item in array using the INDEX value of the array
position.
It provides a way to define and use operators such as +, -, and / for user-defined
classes
or structs. It allows us to define/redefine the way operators work with our classes
and
structs. This allows programmers to make their custom types look and feel like
simple
types such as int and string.
VB.NET till now does not support operator overloading. Operator overloading is
done
by using the Operator keyword.
Note:- Operator overloading is supported in VB.NET 2005
(I) In below sample code if we create a object of class2
which constructor will fire first ?
Public Class Class1
Sub New()
End Sub
End Class
Public Class class2
Inherits Class1
Sub New()
End Sub
End Class
* I leave this to the readers......
(B)Whats the significance of Finalize method in .NET?
.NET Garbage collector does almost all clean up activity for your objects. But
unmanaged
resources (ex: - Windows API created objects, File, Database connection objects,
COM
objects etc) is outside the scope of .NET framework we have to explicitly clean our
Problem with finalize is that garbage collection has to make two rounds in order to
remove
objects which have finalize methods.
Below figure will make things clear regarding the two rounds of garbage collection
rounds
performed for the objects having finalized methods.
In this scenario there are three objects Object1, Object2 and Object3. Object2 has
the
finalize method overridden and remaining objects do not have the finalize method
overridden.
Now when garbage collector runs for the first time it searches for objects whose
memory
has to freed. He sees three objects but only cleans the memory for Object1 and
Object3.
Object2 it pushes to the finalization queue.
Now garbage collector runs for the second time. He sees there are no objects to be
freed
and then checks for the finalization queue and at this moment it clears object2 from
the
memory.
So if you notice that object2 was freed from memory in the second round and not
first.
Thats why the best practice is not to write clean up Non.NET resources in Finalize
IDisposable and override the Dispose method of IDisposable interface. Now once
your
class has exposed the Dispose method its the responsibility of the client to call the
Dispose method to do the cleanup.
(A)How do I force the Dispose method to be called
automatically, as clients can forget to call Dispose method?
Note :- I admire this question.
Call the Dispose method in Finalize method and in Dispose method suppress the
finalize
method using GC.SuppressFinalize. Below is the sample code of the pattern. This is
the
best way we do clean our unallocated resources and yes not to forget we do not get
the hit
of running the Garbage collector twice.
Note:- It will suppress the finalize method thus avoiding the two trip.
Public Class ClsTesting
Implements IDisposable
Public Overloads Sub Dispose()Implements IDisposable.Dispose
' write ytour clean up code here
GC.SuppressFinalize(Me)
End Sub
Protected Overrides Sub Finalize()
Dispose()
End Sub
End Class
(I)In what instances you will declare a constructor to be
private?
When we create a private constructor, we can not create object of the class directly
from
a client. So you will use private constructors when you do not want instances of the
class
to be created by any external client. Example UTILITY functions in project will have
no