Board index » delphi » Discussion proposal
Hechicero
Delphi Developer |
Hechicero
Delphi Developer |
Discussion proposal2004-04-15 01:08:40 AM delphi255 Hi, I'd like to propose a discution to view your point of view. IMHO every method in Delphi sould be virtual and you should specify when you want it to be static. Other People says that every method should be static as it is because of performance. We are having this discusion here at work and I would like to see your point of view. Esteban Calabria |
Ritchie Annand
Delphi Developer |
2004-04-15 04:00:48 AM
Re:Discussion proposal
In article <XXXX@XXXXX.COM>,
XXXX@XXXXX.COM says... QuoteHi, Having static methods is nice for a tiny, tiny bit of performance, although it is more nice in that they can be linked out (although if you ever want to evaluate it in the de{*word*81}, that can be frustrating :) I don't need virtual methods everywhere, though - support methods for virtual methods can easily be static. I would, however, rather see an emphasis on breaking up the classes into manageable pieces. Part of the reason being that many classes (Borland's especially, although they pale compared to some DevExpress components ;) have some virtual methods that contain a lot of branching logic (often due to multiple responsibilities) that you *can't usefully override*, because many of your overriding needs would require that you copy-and-alter the logic. To add insult to injury, the virtual methods often refer directly to private/friend methods and members, and you *can't* copy-and-alter the logic :) Additionally, I'd like to see either pure abstract classes or interfaces for the small pieces. Probably interfaces, since it is hard to make a true 'abstract class' when the reference implementation is based on TComponent. The history of data access would have been a bit different if TDataset was accessed through an interface. The one extra thing you get from interfaces that virtual methods alone doesn't give you is that you can make an entire proxy/delegate. Instead of overriding, you can wrap up a reference implementation completely so, for example, you could ensure, re-establish, or reroute connection to a database if it went down in the middle of an operation instead of throwing an error immediately. Just some thoughts, QuoteEsteban Calabria www.malibugroup.com nimble.nimblebrain.net wiki.nimblebrain.net |
Marc Rohloff
Delphi Developer |
2004-04-15 04:07:50 AM
Re:Discussion proposal
Hechicero wrote on Wed, 14 Apr 2004 14:08:40 -0300 ...
<XXXX@XXXXX.COM> QuoteHi, For example in Java it is easy for someone to unintentionally override a method just by giving it the same signature. It can then be called at unexpected times and break functionality. This is even worse in Java and .NET where the assembly containing the base class can be replaced without requiring the subclasses to be compiled. Marc Rohloff marc rohloff at bigfoot dot com |
Jim Cooper
Delphi Developer |
2004-04-15 06:58:41 AM
Re:Discussion proposalQuoteIMHO every method in Delphi sould be virtual and you should specify when You just need to be clear about what's virtual and what's not, and having to specifically say "virtual" or "static" is really the same thing anyway, just with the complementary set of methods. Note that "static" in C++ or C# is not the same thing (it's like a class method in Delphi, which can itself be virtual or static) QuoteOther People says that every method should be static as it is because of looking at the level of a few extra clock cycles to care. Cheers, Jim Cooper _______________________________________________ Jim Cooper XXXX@XXXXX.COM Falafel Software www.falafelsoft.co.uk _______________________________________________ |
Bob Dawson
Delphi Developer |
2004-04-15 08:27:33 AM
Re:Discussion proposal
"Hechicero" wrote
QuoteIMHO every method in Delphi sould be virtual and you should specify default there too. More a compiler than an oodesign topic though ... bobD |
John Herbster
Delphi Developer |
2004-04-15 09:28:56 AM
Re:Discussion proposal
"Hechicero",
May I suggest that when making your next proposal, that you put the subject in the subject line. Rgds, JohnH |
Bjørge Sæther
Delphi Developer |
2004-04-15 04:45:44 PM
Re:Discussion proposal
Hechicero writes:
QuoteHi, doing what one is supposed to do - derive from them. The problem with e.g. VCL is that decisions on what methods are virtual and what methods are not, is that the VCL developers don't know what Delphi programmers are up to. Especially the DB units I have been forced to modify. But making it all virtual...you would loose information on what the programmer has been thinking. When there is a virtual method TDataSet.DoAfterPost;, you know for sure it is been designed to be overridden by other programmers. When it is static, you know it hasn't been planned for being overridden. It doesn't mean you don't want to override it, though... Because - there is one point being missed: Overriding a method doesn't necessarily mean you want to do the same thing as the ancestor method did, it may well only represent an appropriate spot for hooking into the code. You need to be able to hook into existing code, like setting a field value and then call 'inherited'. Just because that is the point of execution where you need it to be done. -- Regards, Bjørge Sæther XXXX@XXXXX.COM ------------------------------------- I'll not spend any money on American Software products until armed forces are out of Iraq. |
Hechicero
Delphi Developer |
2004-04-16 08:25:23 PM
Re:Discussion proposal
"Marc Rohloff" <XXXX@XXXXX.COM>escribi?en el mensaje
QuoteHechicero wrote on Wed, 14 Apr 2004 14:08:40 -0300 ... Java coder. I agree with you, but IMHO that is not strong enough to support all methods being static. Quote
|
Hechicero
Delphi Developer |
2004-04-16 08:32:33 PM
Re:Discussion proposal
"Jim Cooper" <XXXX@XXXXX.COM>escribi?en el mensaje
Quote
question. Quote
I declare virtual methods when I want to use polimorphism. Since recently I made a desing that use hevy use of polimorphism, I was a little bit tired of declarin every method as virtual in the base classs... Quote>Other People says that every method should be static as it is because of But come on, it is not that slow. Even in some games engines (even H**L**2) they use virtual methods even used in Time critical operations. QuoteI've never seen a situation where that optimisation would make an |
Hechicero
Delphi Developer |
2004-04-16 08:33:54 PM
Re:Discussion proposal
I see it as an OO design topic though.
Actually this discussion came because the fact that every method is no virtual impacted in a design I am currently working on. "Bob Dawson" <XXXX@XXXXX.COM>escribi?en el mensaje Quote"Hechicero" wrote |
Hechicero
Delphi Developer |
2004-04-16 08:45:08 PM
Re:Discussion proposal
Silly of me... You are right...
Let-s look at the bright side... maybe people join the discussion because they see the subject and whant to see what is is about... ) "John Herbster" <herb-sci1_AT_sbcglobal.net>escribi?en el mensaje Quote
|
Jim Cooper
Delphi Developer |
2004-04-20 06:25:38 PM
Re:Discussion proposalQuoteSince recently I made a desing that use hevy use of polimorphism, I was a Quote>>Other People says that every method should be static as it is because of Quote>I've never seen a situation where that optimisation would make an _______________________________________________ Jim Cooper XXXX@XXXXX.COM Falafel Software www.falafelsoft.co.uk _______________________________________________ |
Hechicero
Delphi Developer |
2004-04-28 09:07:55 PM
Re:Discussion proposal
In a proxy pattern we have the subject and the proxy
If someone convinces me in how to implement a Proxy Pattern without making every method of the subject virtual I will consider the posibility of not using as much virtual methods as I do. "Hechicero" <XXXX@XXXXX.COM>escribi?en el mensaje Quote
|
Marc Rohloff
Delphi Developer |
2004-04-28 09:41:19 PM
Re:Discussion proposal
Hechicero wrote on Wed, 28 Apr 2004 10:07:55 -0300 ...
<408fad98$XXXX@XXXXX.COM> QuoteIn a proxy pattern we have the subject and the proxy abstract TStream class is already provided. This implies forethought on behalf of the developer anyway. Proxies can also be created using interfaces which don't require virtual methods. Marc Rohloff marc rohloff at bigfoot dot com |
Hechicero
Delphi Developer |
2004-04-28 10:08:22 PM
Re:Discussion proposal
"Marc Rohloff" <XXXX@XXXXX.COM>escribi?en el mensaje
QuoteHechicero wrote on Wed, 28 Apr 2004 10:07:55 -0300 ... QuoteProxies can also be created using interfaces which don't require virtual |