 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Ant Guest
|
Posted: Sat Feb 19, 2005 1:06 am Post subject: Help please on how to approach this |
|
|
Hello all :)
I am still trying to comprehend all the OO features that Delphi(7) has
to offer, and am struggling with how to implement this design.
I am sure it is not a new idea, but the design I have in mind will
hopefully save me some serious code rewriting in the future.
What I would like to achieve in summary is this.
I want to be able to display some data in any control I choose, whether
this be a treeview, a string grid, a memo or some other control that
appears in the future or that I myself may build.
The source of the data could be from anything
a text file, a dataset, SQL Query, a cds database or just about anything.
These are my thoughts on how I could implement this, but I am not
experienced enough or confident enought to know how to start this.
The idea is basically this
A Parent class with some basic virtual functions that will apply to the
decendant classes
these would be
Display( used to show the data in the control )
Update ( used to update data in the control due to changes from data
source )
GetData ( used to obtain the data source )
These I imagine will apply to the Majority of controls I would use to
represent this data.
I would call the Parent Class DataView or something
I would then inherit from this class and implement the inherited virtual
functions specific to that control.
For instance the treeview control would require the most work out of all
the controls I would imagine, especially if it is represent the data in
a heirarchal view, lots of thing would need to happen like building tree
nodes, images to represent the nodes (possibly).
Now in the view part of my program I just want the view part of the
program to display the data according to the control selected.
and the control would know how to respond to certain events, like a
refresh ( the update function )
draw ( display function )
load data ( get data function ).
I know this has something to do with Polymorphism, and that by declaring
the Parent class functions as virtual, and implementing these in the
derived classes, I would simply create an object of Dataview, and assign
it reference of one of the controls and then by simply calling the
function, it will execute the correct function according to the control
it has reference to?
I have also read about design patterns, unfortunately I don't seem to
have understood them as well as I thought.
I once read a really interesting article on Joanna Carter's teamb blog
page on MVP, but sadly this does not seem to be there any longer.
I am not entirely sure this is what I would be needing anyway, as
controls will most likely be known at design time, with a possibilty of
of dynamic controls being added.
All I want to achieve is a type of framework that in the future will
allow me to reuse these class framework in any new apps I build with
little or no recoding.
For instance one app might implement a treeview, and by simply adding
this to the form and implementing some code to use the Dataview classes
will just work, by using the prebuilt classes.
I have also seen a very very brief intro of Interfaces, and am unsure if
this would fit in better than classes?
Any advice ( except dont do it ) pointers, links to tutorials or
anything that would allow me to implement this before it becomes a
fragmented patrticle floating around in the brain :)
Thanks in advance, sorry the post is a bit long
|
|
| Back to top |
|
 |
Joanna Carter (TeamB) Guest
|
Posted: Sat Feb 19, 2005 9:28 am Post subject: Re: Help please on how to approach this |
|
|
"Ant" <Ant (AT) nowhere (DOT) com> a écrit dans le message de news:
[email]42169116 (AT) newsgroups (DOT) borland.com[/email]...
| Quote: | I want to be able to display some data in any control I choose, whether
this be a treeview, a string grid, a memo or some other control that
appears in the future or that I myself may build.
|
You certainly do need the MVP framework for something like this; it totally
separates the UI from the BO layer and you could always adapt it so that the
View classes were Adapters that know how to talk to a control rather than
being a control.
| Quote: | I once read a really interesting article on Joanna Carter's teamb blog
page on MVP, but sadly this does not seem to be there any longer.
|
The articles are on my website www.carterconsulting.org.uk
You would also benefit from looking at OPFs (Object Persistence Frameworks)
as these will separate out all the data manipulation code from you business
logic.
Both MVP and OPF are better facilitated by using using a Value Type
Framework rather than relying on RTTI and you want to Google on this group
for the many discussions and examples that have been posted here.
| Quote: | I have also seen a very very brief intro of Interfaces, and am unsure if
this would fit in better than classes?
|
Jim Cooper and I are at variance on this, but I found in Delphi for Win32,
once you have started you have to use them almost everywhere, due to the
problems with reference counting and the inability to cast from an interface
to an object. Interfaces are useful but not as necessary in .NET; my designs
for .NET don't use anywhere near as many interfaces as they did for Win32.
Joanna
--
Joanna Carter (TeamB)
Consultant Software Engineer
TeamBUG support for UK-BUG
TeamMM support for ModelMaker
|
|
| Back to top |
|
 |
Ant Guest
|
Posted: Sun Feb 20, 2005 8:12 pm Post subject: Re: Help please on how to approach this |
|
|
| Quote: | I want to be able to display some data in any control I choose, whether
this be a treeview, a string grid, a memo or some other control that
appears in the future or that I myself may build.
You certainly do need the MVP framework for something like this; it totally
separates the UI from the BO layer and you could always adapt it so that the
View classes were Adapters that know how to talk to a control rather than
being a control.
|
Hello
I just read your object store.zip articles, and found them very
interesting, even though, I do not fully understand this yet.
I think I may have done something like the MVP I am not sure.
What I did was to Create a TreeViewHandler that took as an argument to
it's constructor the treeview on the form, and a data source (currently
a Stringlist container, which I got from Marco Cantu's Mastering Delphi
7 book made from a tab delimited file Using Peter Bellows String Parser
Function ).
And this then builds the data for the treeview in this class, a variable
of this class is declared in the main form, so that it exists as long as
the TTreeVIew control does.
It uses a proxyNode class that holds a reference to a recordNode object
in an object list, that holds all the record data.
the TTreeNode Data property holds a pointer to the proxyNode, the Proxy
node Hold the ID of the Record Node it Points to which is the same as
the record id from the file or db, and also two other fields that are
used to create a description for the TTReeNode.
The problem with this TreeViewHandler Class right now is it is very
specific to one database or textfile, all the fields for the RecordNode
are hardcoded to match the database/text file.
So I guess I am sort of on the right track here, but if I need to use
this for another database, I would have to change the hardcoded
filednames of the class, probably not a big thing now, but could get
complicated as I had more functionality to the class that may have a
dependency on certain fieldnames of the class.
| Quote: | You would also benefit from looking at OPFs (Object Persistence Frameworks)
as these will separate out all the data manipulation code from you business
logic.
Both MVP and OPF are better facilitated by using using a Value Type
Framework rather than relying on RTTI and you want to Google on this group
for the many discussions and examples that have been posted here.
|
Ok now I would like to give my interpretation of the OPF, as I
understand it, and welcome any corrections along the way :)
A Business Object is an object that holds the fields of a record from a
database for flatfile in an object?
A collection of BO's are a list containing each created BO?
The business logic is yet another object that holds the business rules
about how and what data should be used, that will also hold a reference
to a BO to see what fields the business logic will use?
Then there are the graphic controls which re derivations of common
Delphi controls, customised for use with Business Object and Business
Logic, they represent the view of the data.
However these controls are not tied to one particular type of BO or BL
they will just have these as a reference and know how to display the
data contained t=in the BO using the BL?
So it could be summed up as something like this.
BO = Business Object = Holds fieldnames from a data source
BL = Business Logic = Holds all the functions procedures etc that
manipulate the BO, maybe SQL Selects, Updates etc, grouping orders, and
any busines rules that apply to the data, but instead of manipulating a
database record they manipulate a BO?
Views = Graphic Delphi controls = take a BO as a reference and display
the data related to the filednames of the BO, regardless of what
Fieldnames exist in the BO?
| Quote: |
I have also seen a very very brief intro of Interfaces, and am unsure if
this would fit in better than classes?
|
I still do not understand Interfaces, or rather how they should not be
used with object references due to reference counting etc, I thought the
idea of an interface was to allow for emulated multiple Inheritance So
somewhere along the way an Object is going to have to exist somewhere
that implements the interface?
Your thoughts and comments welcome as to my understanding of OPF
TIA
|
|
| Back to top |
|
 |
Joanna Carter (TeamB) Guest
|
Posted: Mon Feb 21, 2005 10:45 am Post subject: Re: Help please on how to approach this |
|
|
"Ant" <Ant (AT) nowhere (DOT) com> a écrit dans le message de news:
4218ef11$1 (AT) newsgroups (DOT) borland.com...
| Quote: | I just read your object store.zip articles, and found them very
interesting, even though, I do not fully understand this yet.
|
Don't worry, it took me two years to to get enough understanding to write
them :-)
| Quote: | The problem with this TreeViewHandler Class right now is it is very
specific to one database or textfile, all the fields for the RecordNode
are hardcoded to match the database/text file.
|
This is not MVP, it is OPF. The OPF should take an object and delegate the
retrievel/storage to a base handler type which should have any methods that
are common to all operations related to retrieving/storing an object.
You then derive from the base handler class to allow you database-specific
code. You can then choose which handler you want to use, even at runtime.
| Quote: | So I guess I am sort of on the right track here, but if I need to use
this for another database, I would have to change the hardcoded
filednames of the class, probably not a big thing now, but could get
complicated as I had more functionality to the class that may have a
dependency on certain fieldnames of the class.
|
The OPF handler should look after the translation of property names to/from
field names.
| Quote: | Ok now I would like to give my interpretation of the OPF, as I
understand it, and welcome any corrections along the way :)
A Business Object is an object that holds the fields of a record from a
database for flatfile in an object?
|
No, no, no!! Business Objects know nothing about databases at all. As I
have just said, it is the responsibility of the OPF handlers to translate
objects to tables.
| Quote: | A collection of BO's are a list containing each created BO?
|
Yes
| Quote: | The business logic is yet another object that holds the business rules
about how and what data should be used, that will also hold a reference
to a BO to see what fields the business logic will use?
|
Business logic can appear in both storable Bos and also BOs that are
'managers'.
Most BOs have their own internal logic that manages their own
responsibilities; things like calculating an Invoice Total from the Invoice
Lines held inside the Invoice object.
There are also other BOs whse responsibilities affect more than one type of
object; for example, storing a Sales Order also affects the Customer Total
Balance as well as the Stock Level for each Product included in the Order.
This logic does not truly belong in any one class as it then ties that logic
to a class that may not be able to see the entire BO model.
| Quote: | Then there are the graphic controls which re derivations of common
Delphi controls, customised for use with Business Object and Business
Logic, they represent the view of the data.
|
This is more to do with MVP.
| Quote: | However these controls are not tied to one particular type of BO or BL
they will just have these as a reference and know how to display the
data contained t=in the BO using the BL?
|
Certain controls can display any value type or list of objects, but you may
need to derive custom controls for complex objects.
| Quote: | So it could be summed up as something like this.
BO = Business Object = Holds fieldnames from a data source
|
No
| Quote: | BL = Business Logic = Holds all the functions procedures etc that
manipulate the BO, maybe SQL Selects, Updates etc, grouping orders, and
any busines rules that apply to the data, but instead of manipulating a
database record they manipulate a BO?
|
No, BL is an integral part of a BO
| Quote: | Views = Graphic Delphi controls = take a BO as a reference and display
the data related to the filednames of the BO, regardless of what
Fieldnames exist in the BO?
|
Not quite. A View displays the properties of a BO; it has no knowledge of
databases, fields or tables.
| Quote: | I still do not understand Interfaces, or rather how they should not be
used with object references due to reference counting etc, I thought the
idea of an interface was to allow for emulated multiple Inheritance So
somewhere along the way an Object is going to have to exist somewhere
that implements the interface?
|
If I were you, I would take it one step at a time and try to clear up your
understanding of classes before you move into interfaces :-)
Joanna
--
Joanna Carter (TeamB)
Consultant Software Engineer
TeamBUG support for UK-BUG
TeamMM support for ModelMaker
|
|
| Back to top |
|
 |
Ant Guest
|
Posted: Mon Feb 21, 2005 11:54 am Post subject: Re: Help please on how to approach this |
|
|
| Quote: | Don't worry, it took me two years to to get enough understanding to write
them
|
That makes me feel better :)
I think I need to do some more research/reading of this OPF thingy
It took me a while to grasp basic OO polymorphism and inheritance.
I know what I need, but do not understand enough to be able to
implement this yet, which I find frustrating, hopefully practice will
make things easier.
I never really settled with any language during college, and learnt
bits of C++, bits of Java, and bits of VB, but never felt entirely
comfortable with any of these least of all Java.
It wasn't until I found an article describing how to do something in
Delphi that I started using Delphi, and glad I did, although I still
try to learn C++ as well.
Thanks for the help so far, I am off googling now until I understand
more about this OPF idiom and will then no doubt return with more
question
Thanks
|
|
| Back to top |
|
 |
Joanna Carter (TeamB) Guest
|
Posted: Mon Feb 21, 2005 1:17 pm Post subject: Re: Help please on how to approach this |
|
|
"Ant" <Ant (AT) nowhere (DOT) com> a écrit dans le message de news:
4219cbab$1 (AT) newsgroups (DOT) borland.com...
| Quote: | It wasn't until I found an article describing how to do something in
Delphi that I started using Delphi, and glad I did, although I still
try to learn C++ as well.
|
With the advent of .NET, you would be advised to move on to C#; it is very
similar to C++ but without some of the peculiarities and gotchas, and it
allows you to be able to write code in either Delphi or C# against the .NET
runtime.
Joanna
--
Joanna Carter (TeamB)
Consultant Software Engineer
TeamBUG support for UK-BUG
TeamMM support for ModelMaker
|
|
| Back to top |
|
 |
Ant Guest
|
Posted: Mon Feb 21, 2005 2:16 pm Post subject: Re: Help please on how to approach this |
|
|
Joanna Carter (TeamB) wrote:
| Quote: | "Ant" <Ant (AT) nowhere (DOT) com> a écrit dans le message de news:
4219cbab$1 (AT) newsgroups (DOT) borland.com...
With the advent of .NET, you would be advised to move on to C#; it is very
similar to C++ but without some of the peculiarities and gotchas, and it
allows you to be able to write code in either Delphi or C# against the .NET
runtime.
|
I looked at C# early on, and was uncertain of C#'s future, I have
heard many bad things and many good things about the language, one of
the reasons I did not look at .Net is because our tutor told us
''.Net is not used anywhere near as much as Microsoft would have us
believe, and many businesses are sceptical about using the .Net until
it has proven not to be a new portal for the evils of worms and
viruses.''
As to the merits of this I do not know, Delphi 8 came with my version
of Delphi 7, but I have never used it.
I think I need to stick to Delphi at the moment and try and learn and
understand this powerful language before looking at others, the
reason I still learn C++ as well is because I am still completing an
online course.
Delphi seems to offer a lot of what C++ does apart from MI, which as
far as I can see I have never needed yet, and of course Delphi uses
mainly references rather than pointers.
I notice that Borland are also offering a C# solution perhaps in 6
monts from now, I can look at broadening my programming language
skills to newer languages, I think mastering OOP will make things easier.
From my little experience I have in programming so far one language
is like the next differing only in syntax, and flexibility it
allows the programmer, I can happily implement a stack in C++, Delphi
or VB it will only be the syntax and how easily the language enables
me to implement this that will be different, and perhaps limitations
on what data types the stack could hold.
Thank you for all the help and advice you have chosen to share, it is
very much appreciated, and I no doubt will be picking your brains for
more information sooner rather than later
Thanks
|
|
| Back to top |
|
 |
Lee_Nover Guest
|
Posted: Mon Feb 21, 2005 2:20 pm Post subject: Re: Help please on how to approach this |
|
|
| Quote: | I want to be able to display some data in any control I choose, whether
this be a treeview, a string grid, a memo or some other control that
appears in the future or that I myself may build.
maybe something like this: |
http://leenover.homeip.net/isapi/pas2html.dll/pas2html?File=/delphi/projects/PyramidSales/
it's a really small example presenting data in a virtual treeview
there are only presenters for the VTV but others can easily be added
no real BO logic there .. just some examples
this was actually my first try at a simple MVP .. it probably should have
more classes that would really separate M from V from P :)
|
|
| Back to top |
|
 |
Joanna Carter (TeamB) Guest
|
Posted: Mon Feb 21, 2005 4:03 pm Post subject: Re: Help please on how to approach this |
|
|
"Ant" <Ant (AT) nowhere (DOT) com> a écrit dans le message de news:
4219ecd5$1 (AT) newsgroups (DOT) borland.com...
| Quote: | I think I need to stick to Delphi at the moment and try and learn and
understand this powerful language before looking at others, the
reason I still learn C++ as well is because I am still completing an
online course.
Delphi seems to offer a lot of what C++ does apart from MI, which as
far as I can see I have never needed yet, and of course Delphi uses
mainly references rather than pointers.
|
There certainly isn't much mainstream programming that can't be done in
Delphi.
BTW Delphi does use pointers; every object variable is really a pointer,
it's just that you don't have to explicitly de-reference them, that is taken
care of by the compiler.
| Quote: | I notice that Borland are also offering a C# solution perhaps in 6
monts from now, I can look at broadening my programming language
skills to newer languages, I think mastering OOP will make things easier.
|
Certainly, if you se the need to move to .NET, then Delphi 2005 is an ideal
transitional tool as it supports Delphi for Win32, Delphi for .NET and C#,
all in the one product.
Joanna
--
Joanna Carter (TeamB)
Consultant Software Engineer
TeamBUG support for UK-BUG
TeamMM support for ModelMaker
|
|
| Back to top |
|
 |
Ant Guest
|
Posted: Tue Feb 22, 2005 6:37 pm Post subject: Re: Help please on how to approach this |
|
|
Hi Lee
Thanks very much for this, it is very helpful
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|