Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Instantiation gobbly gook

Status
Not open for further replies.

tedsmith

Programmer
Joined
Nov 23, 2000
Messages
1,762
Location
AU
Can anybody really explain in simple terms with a simple example the term "instantiation"

I thought I knew what it meant but this definition from another site has me now completely confused:-

"In programming, instantiation is the creation of a real instance or particular realization of an abstraction or template such as a class of objects or a computer process. To instantiate is to create such an instance by, for example, defining one particular variation of object within a class, giving it a name, and locating it in some physical place.
 
The reason they appear as snippets rahter than being grouped together in a module is because the same Sub or Function can often be used by many other processes otherwise they have to be repeated and the code becomes much larger, or else you'd end up with 100 modules which is just as bad.
Consider this same Sub using a function to open and close a database that can be used by many other different procedures just by changing the input variables:

Sub SendToBusStop (BusStop)
if QueryMyDataBase BusStop, MyDatabase, "Select * From MyTable etc. etc.. , True = True then
Winsock (BusStop).SendData MyRec!DeptTime
End If
QueryMyDataBase ,,,False 'close it
End Sub

Function QueryMyDatabase (BusStop, Database, Criteria, OpenClose as Boolean)
If OpenClose=True then
OpenDatabase DataBase
OpenRecordset Criteria
QueryMyDatabase = MyRec.NoMatch
Else
Close Dynaset
Close DataBase
Set Recordset = Nothing
Set DataBase = Nothing
End IF
End Function

What would an OOP alternative be ?

 
I am sorry that a couple of people have assumed I was championing one method of programming over another because I certainly have not intended this question in any way and didn't want to get into a philosophical argument.

As I said I simply want to know how I can improve my programming and why one method is better than another and whether it is just a matter of style or does it give a real benefit to the final operation of the application?

The reason I haven't used class modules is simply that I couldn't see any advantage in doing so.
The real advantage that others claim I would get is what I want to learn about.
 
tedsmith said:
What would an OOP alternative be ?
Procedures like your QueryMyDatabase I would put in a static ("shared" in VB.NET terminology) class, so in code that calls it might look something like:
Code:
   if ApplicationDatabase.QueryMyDataBase(BusStop, MyDatabase, "Select * From MyTable etc. etc.. , True) = True Then
       Winsock (BusStop).SendData MyRec!DeptTime
   End If

tedsmith said:
whether it is just a matter of style or does it give a real benefit to the final operation of the application?
It is a matter of style. If you are asking if OO creates more efficient code, then the answer is no. QueryMyDataBase as a method in a class, as opposed to being a function in a module, will have the exact same code either way.

The benefits of OO is in the organization of the code. This is not so obvious with small projects. But big projects need a sophisticated organization, otherwise things break down pretty quickly. Also, code organized in classes tends to be much easier to reuse than large libraries of functions.
 
Thanks for clearing that up and confirming my original concept of class.
I obviously misconstrued what others said in thinking otherwise.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top