2. Index
A. Object Oriented Programming
1. Class
2.Constructor and Destructor
3.Inheritance
4.Overridden
5.Overloading
6.Polymorphism
7.Interfaces
8. Implementing Polymorphism using
Interfaces
B. Multithreaded Programming
1. Thread Synchronization
2. Events and Thread Synchronization
3. Polymorphism
• Different classes that have same properties
and methods
• Classes represent have similar operation and
characteristics
• Example
Vehicle - base class
each type of
vehicle derive from vehicle class
see eg in your book
4. • Class Truck inherits Vehicle
which contain procedure and function like
1.function start engine
2. stop engine
3.function accelerate
• Class minivan inherits vehicle
which also contain the same function and procedure in the same name
what truck has.
• Next create one object objvehicle through procedure (Dovehicleoperation)
to call all the function and procedure from both derived class(truck and
minivan)
• Create object for individual derived class
dim objtruck as new truck()
dim objminivan as new minivan()
• Execute individual derived class function and procedure by substituting
each derived class object in Dovehicleoperation procedure
Dovehicleoperation (objtruck)
Dovehicleoperation(objminivan)
5. From the previous example polymorphism is many form
like truck and minivan which has same name methods
and characteristics as base class
• Polymorphism provides following features:
• It allows you to invoke methods of derived class
through base class reference during runtime.
• It has the ability for classes to provide different
implementations of methods that are called through
the same name.
• Advantage of polymorphism:
• It helps programmers to reuse the code, classes,
methods written once, tested and implemented. They
may be reused in many ways. The single variable name
can be used to store variables of multiple data types
such as Int, Float, double, Long, etc).
6. Interfaces
• An interface is a specification for a set of class
members, properties, and methods but do
not provide any implementation.
An Interface is a reference type and it contains
only abstract members such as Events,
Methods, Properties etc. It contain only
declaration for its members and
implementation defined as separate entities
from classes.
7. • Create one interface imyclassinterface, which
contains procedure (myproc,yourproc) and
functions(anybodysproc)
• Create class cmyclass implements
imyclassinterface
The class contains the same procedure
and function what the interface has.but all the
class procedure and function should
implement through interface procedure
for eg
public sub myproc implements
imyclassinterface.myproc
8. • All the class procedure should implement
through interface procedure.
• Next Create object for both interface and
class. The class name for both of them are
same.
dim objmyclass as imyclassinterface
dim blnreturnvalue as boolean
objmyclass = new cmyclass()
Through the object we can call procedure and
functions within the class
10. • Interface imyalternativeclassinterface inherits
imyclassinterface
One procedure (myaltsub) for derived interface
Create an object for derived interface with same
name objmyclass.
To call both interface procedure add both
interface within the class by
public class cmyclass implements
imyclassinterface, imyalternativeclassinterface
then objmyclass.myproc(1)
Objmyclass.myaltsub()……
11. Implementing Polymorphism using
Interfaces
• In an inheritance ,single class implements
different interfaces like
public class cmyclass implements
imyclassinterface, imyalternativeclassinterface
in the case of polymorphism two different
classes share an interface
Interface igameweapon which contain
property(numofrounds),function(fire) and
procedure(reload)
12. • Two classes
1. public class cmachinegun implements igameweapon
2. public class crocketlauncher implements igameweapon
Both class contains the same property,function and procedure what an
interface has.
• Next create object for interface through one procedure
reloadandattack .
• Next create object for both class .here the object name need not be
same as interface object.
dim objmachinegun as new cmachinegn()
dim objrocketlauncher as new crocketlauncher()
to call the procedure and function of each class through interface
object
• Reloadandattack(objmachinegun)
• Reloadandattack(objrocketlauncher)
13. Multithreaded programming
• Execution follows a single path called a thread.
• In a single threaded application the task like user
input, sorting the large datalist, sending the list to
some application are executed sequentially even
if they are independent task.
• A web server will not do a single threaded
application.it needs to handle thousands of
simultaneous request .
• The solution to maximize the hardware resources
to make the application multithreaded.In .net it is
called free-threaded.
14. • In .net the class object like
system.threading.thread will do threading function
For eg
take two thread
fnction(threadoneproc,threadtwoproc).each function print
out a message that identifies itself 200 times.
Next create object for each thread
dim thd1 as new system,threading.thread(Address of
threadoneproc)
dim thd2 as new system,threading.thread(Address of
threadtwoproc)
Execute both thread function by calling
thd1.start()
Thd2.start().here the start() function will execute both thread.
15. Thread synchronization
• In a free threaded application more than one
thread can occur simultaneously. One of the
problem with free threaded is able to
coordinate thread that operate on the same
set of data.coordinating thread is called
thread synchronization.
• Two methods are sed to synchronize threads
by using IsAlive()
16. • Two threads sort() and printlist()
• Create object for the class then create object
for both threads.
• Here isalive functionis used to check the first
thread is running or not .after completing
sort() ,the sorted list to be printed.
17. Events and thread Synchronization
• An event is a type of signal that we can attach with a class.
That signal can be activated when something happens
inside the class. The event then handled by the host.
• Event is a set of code defined within the class.
Eg public Event somethinghappened().
• Eg for raise event definition
RaiseEvent somethinghappened().
• Declaration of event within the class
dim withevents objmyclass as cmyclassthathasevents
event object classname
18. • In the eg program
two events has been defined
public event progress()
public event done()
And declared as
dim withevents objlist as cnumberlist
Event raise can be defined as
raiseevent progress can be written within the
sort program to check whether all 1500 numbers
have been sorted. If it is not ,again the loop will
be return back to progress
Raiseevent done() .this is another raise event will be
aised after the completion of sorting
19. • To execute event with synchronization
1. create object for thread to sort procedure either to
start the procedure or stop the procedure
thdsortthread.start()
thdsortthread.abort()
2. write procedre for both events with handles
public sub objlist_progress () handles objlist.progress
this procedure is to display how much % of sorting
has been completed.
public sub objlist_done() handles objlist.done()
this procedure is to take printout.since done means the
sorting is over
20. • Students please study this portion which I
have not covered in the class. Other portion I
have covered in the class itself. Go through the
entire syllabus. Study well . Stay at home
safely. Complete the record work . Do practice
your Lab exercises.
Wish you all the Best