Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Is there any way around this issue?
Message
From
30/05/2003 13:27:10
 
 
To
30/05/2003 13:15:21
General information
Forum:
Visual FoxPro
Category:
Classes - VCX
Miscellaneous
Thread ID:
00793727
Message ID:
00794630
Views:
23
Hi Jim,
I'm still missing it.
Doesn't Mario's example just demonstrate the value of inheritance in sub-classes?
I don't see how it demonstrates a need for an "abstract" class that never gets used.
Or am I really blind?


>Well it does give the scholarly types yet another bamboozling mechanism < s >.
>
>I must say, though, that I think Mario's example is a good one.
>
>
>>Hi Mario,
>>
>>I understand inheritance with sub-classes.
>>What I don't understand is why I should have a level of "abstract" classes (that's never used) between VFP's BaseClasses and my "concrete" myBase classes that I use to create objects with. When I need different behavior I create a sub-class from myBase, but when I want a universal change I just modify myBase. What does the "abstract" class accomplish?
>>
>>
>>>Abstract classes area like interfaces. You can provide the definition of a funtion/method/property and OBLIGATE to implement this in a derived class..
>>>
>>>For example, if you want create a backup solution, but need backup not only normal files, but also Sql Server databases, Outlook configurations, etc.. you can:
>>>
>>>TAbstractBackup
>>> Name:String
>>> Directory:String
>>> Date:DateTime
>>> Prepare() Abstract
>>> CanBackup:Boolean Abstract
>>> DoBackup Abstract
>>> CreateFileName
>>> oZip.FileName=Directory+"\"+Name+" "+TRANSFORM(Date)+".zip"
>>> oZip.Create
>>>End
>>>
>>>TFileBackup
>>> File:String
>>> CanBackup
>>> RETURN Directory(JustPath(this.File)) //check if the dir exist...
>>> Prepare
>>> 'Nothing
>>> DoBackup
>>> CreateFileName
>>> oZip.AddFile(this.File)
>>>End
>>>
>>>TDBSqlBackup
>>> Server:String
>>> DBName:String
>>> UserName:String
>>> Password:String
>>> FFileBak:String
>>> CanBacup
>>> return oCon.Open("here the connection string")
>>> Prepare
>>> 'Run the backup in Sql Server a store the .BAK File path
>>> FFileBack=...
>>> 'Optional Shinrk the database
>>> DoBackup
>>> CreateFileName
>>> oZip.AddFile(this.FFileBak)
>>> DELETE FILE (this.FFileBak) //not bloat the harddisk!
>>> oCon.Close()
>>>End
>>>NOTE: Not real code here!
>>>
>>>So, you can see that backup a file is a diferent thing that backup a database. So, is impractical provide a base code for example to DoBackup because you need perform a complete diferent process for a file and to a database, BUT you need force that DoBackup have implementation code, and in this way, you know that TAbstractBackup NEVER must be instantiate (i think that VFP not enforce this, but Delphi & others yes). This is also the idea with a interface, but a Abstract Class can provide base code if need them (but a interface not have never implementation code). In this way, with a factory pattern and maybe a interface you not need worry if a object to backup is a file or something like, your simply do:
>>>
>>>For i=1 To oBackupsItem.Count
>>> oBackupsItem(i).DoBackup
Bill Morris
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform