Newsgroup: it.comp.lang.delphi
Titolo: [OT] Microsoft sostiene che VB6 è OO

Come postato dal buon Morde
 
http://msdn.microsoft.com/en-us/library/aa239699.aspx
--- posted by geoForum on 
http://www.delphiedintorni.it

A proposito c'è un corso x i pivelli del NG
http://www.elementk.com/s.asp?p=66587



http://www.elementk.com/s.asp?p=66587
"This three-hour online learning course teaches the Visual Basic 6.0
developer how to benefit from an object oriented approach to
application development with Visual Basic 2005"
Dai trollino, hai trollato abbastanza, ora rintanati nella tua
celletta.


Sei troppo IDIOTA cazzo leggi bene...


>Sei troppo IDIOTA cazzo leggi bene...
Programming with Class
This article may contain URLs that were valid when originally published, 
but now link to sites or pages that no longer exist. To maintain the 
flow of the article, we've left these URLs in the text, but disabled the 
links.
June 2001
 
 
Get the Most From OOP
Use these 10 top techniques to maximize the benefits of object-oriented 
programming.
by Deborah Kurata 
Reprinted with permission from Visual Basic Programmer's Journal, June 
2001, Volume 11, Issue 6, Copyright 2001, Fawcette Technical 
Publications, Palo Alto, CA, USA. To subscribe, call 
1-800-848-5523
, 650-
833-7100, visit 
www.vbpj.com
, or visit The Development Exchange.
  Taking a step back and examining your application is useful from time 
to time. You can think about whether the application does what it's 
supposed to do, whether you're following best practices, and whether 
better ways exist to achieve your goals. This column presents 10 top 
object-oriented programming techniques to help with your evaluation.
What you need:
Visual Basic 6.0  
 
1. I Do Declare
How you declare your object variable can have a significant impact on 
that object's use and performance. You should use this syntax: 
Private m_oCust As CCustomer
Be sure to use the correct scope. In most cases, you want the object 
variable to be private. If you need the object only in a particular 
routine, you can declare it private to that routine using Dim. If you 
need it throughout the class or form module, you declare it at the top 
of that class or form using Private. By convention, you prefix variables 
declared at the module level with an "m_" for module-level or member 
variables. If you need to access the object variable from outside the 
class, don't make the variable Public. Rather, define a Property Get 
procedure to expose the object variable. This prevents other code from 
using the variable in any other way than you intend. 
Always use the class name and not "As Object" in the declaration because 
using "As Object" makes the object variable late-bound. This means 
Visual Basic doesn't know the type of object you will use until run 
time, so it can't give you auto list members (the dropdown list of the 
object's properties and methods). More importantly, at run time you take 
a significant performance hit over early-bound objects.
Finally, don't use the "New" keyword on the declaration. Using the New 
keyword creates the object automatically any time you reference it. This 
has a slight performance impact because each property and method call on 
the object must check to determine whether the object is created. Using 
the New keyword can cause debugging nightmares because the application 
re-creates the object automatically after it's destroyed if you 
reference the object again inadvertently. Understanding this is even 
more important as you prepare to move to Microsoft .NET because the New 
keyword has a different meaning. In Microsoft .NET, the New keyword 
allows you to create an object when you declare it:
Private mo_Cust as New CCustomer()
This statement creates a new Customer object.
2. Clean Up After Yourself
Be sure to release your object variables when you no longer need them. 
VB then destroys the object associated with the variable, freeing up 
memory in your application.
Use this code to release an object:
Set x = Nothing
3. Encapsulate
Encapsulate means literally to enclose or "put in a nutshell." From an 
object-oriented programming (OOP) perspective, this means to put all the 
data and processing associated with an object in its class. No more, no 
less.
Encapsulation is sometimes referred to as information hiding because you 
hide the object's data within the class. If other classes need access to 
the data, you can expose the data using property procedures (property 
statements in Microsoft .NET). This action gives the class control over 
how users can view or update the data and prevents other objects from 
corrupting that data.
Encapsulation simplifies the interactions between objects. An object can 
use another object without knowing all its data or how its data is 
maintained. For example, a Customer object might have name and address 
properties, as well as a phone number, credit history, and other related 
fields. If an Invoice object wants to use a Customer object, it can 
request the name and address for the invoice without needing to know 
where the Customer object obtained that data or what the other data 
elements are.
In my previous column, I demonstrated how to encapsulate the Document 
Object Model (DOM) for Extensible Markup Language (XML) in a wrapper 
class. This allows you to interact more easily with an XML file without 
needing to know the DOM's details.
4. Watch Your State
Good component-based development techniques require stateless objects 
frequently. Stateless objects have no retained properties, only methods. 
You can access a stateless component, execute methods, and complete 
processing without maintaining any data between method calls.
Some OOP literature suggests that an object without properties is not an 
object. Ignoring this semantic issue, you can create classes with 
methods and no properties. You often want to do this when working with 
COM+ or Web development. An Active Server Page can execute a method on a 
component to perform specific processing, then release the component 
without concern for managing object state.
5. Pass Parameters
Parameters provide a way to pass information to and from a class's 
methods. You need parameters to pass any necessary data to the method, 
especially if you require stateless objects.
For example, the PlaceOrder method of a stateless Customer object needs 
the customer information passed to it as parameters. The PlaceOrder 
method then uses this information to perform the necessary processing.
As you define your methods' parameters, be sure to make them extensible. 
For example, this line of code is not extensible:
Public Function PlaceOrder(sLastName as String, _
	sFirstName as String, sAddress as String)
You must pass in the three parameters to call this method. If you decide 
later you also want the phone number on the order, you must change the 
function signature, breaking compatibility and every developer's code 
that uses this method. A better technique: Pass the parameters in a 
container. You can use a recordset, variable array, or XML string to 
pass in parameters more generically.
This tip is less necessary as you move to Microsoft .NET because you can 
do function overloading, whereby you can have the same function with two 
different sets of parameters:
Public Function PlaceOrder(sLastName _
	as String, sFirstName as String, sAddress as String)
Public Function PlaceOrder(sLastName _
	as String, sFirstName as String, _
	sAddress as String, sPhone as String)
6. Use XML
XML provides a great way to maintain state and pass it between your 
application's components. You can define your XML in any desired format. 
You can then insert, update, delete, or review any information from the 
XML string.
The best thing about XML is that it's platform- and vendor-independent. 
XML is neither a Microsoft technology nor a Sun technology. Rather, the 
World Wide Web Consortium (W3C) controls this standard.
XML is the upcoming data access standard in Microsoft .NET, so using it 
now will give you a head start.
7. Define Interfaces
Interfaces provide a great way to plug in components at run time. You 
can define an interface and build a class that implements it. Then you 
can replace the class easily at any time with any other class that 
implements the same interface.
For example, you can develop a mailing list label-printing component and 
define the standard interface the component requires. In this example, 
that interface includes name and address information. Any class that 
implements this interface can then use the component without making any 
changes to it. A customer class that implements the label-printing 
interface can use the component to print customer mailing labels. An 
employee class that implements the label-printing interface can use the 
component to print paycheck mailing labels and so on.
 
Figure 1 | Create a Domain Model Click here.
 
8. Inherit Base Functionality
Inheritance, a key principle of OOP, allows you to define an object's 
base functionality, then use that functionality for specific subtypes of 
the object.
For example, you can define base functionality for a Customer object 
that allows you to retrieve and save data and calculate a discount. You 
can then define a government Customer object that inherits all the 
customer functionality but overrides the discount calculation to give a 
better discount to government customers.
You can't do this one now, but it's in Microsoft 
VB.NET
, so you will be 
able to do it soon. For now, you might consider where inheritance makes 
sense in your application to prepare for this feature.
9. Model It
Developing a domain model to depict the business is useful in 
understanding your application's purpose and the problem it should solve 
(see Figure 1).
However, a common mistake is to take that domain model and attempt to 
code from it. Rather, you need to morph that domain model into an 
implementation model that defines how you should build the classes. You 
need to consider several factors when morphing the domain model into an 
implementation model (see the sidebar, "Work With Object Models").
10. Know It, Live It
All of Microsoft .NET is object-oriented. The more you know and 
understand about OOP now, the easier your transition to Microsoft .NET 
will be. Get prepared by using class models in all your projects. If you 
don't know OOP, or you know it but don't really understand it, take an 
OOP class now. Follow conversations on DevX about objects and 
Microsoft .NET. Go to conferences and local user groups to expand your 
OOP exposure or share your OOP experiences with others. Soon, OOP 
techniques will become second nature to you, and you might find it hard 
to remember how you coded before!
Deborah Kurata is a cofounder of InStep Technologies Inc., a consulting 
company that specializes in designing and developing Web and Windows 
applications (
www.insteptech.com
). She's the author of Doing Objects in 
Visual Basic 6 (Sams), which focuses on a pragmatic approach to object-
oriented design and development. Reach her by e-mail at 
debo...@insteptech.com
.
