polymorphism (was Re: Type checking in python?)
Richard Brodie
R.Brodie at rl.ac.uk
Wed Jul 26 11:54:30 EDT 2000
More information about the Python-list mailing list
Wed Jul 26 11:54:30 EDT 2000
- Previous message (by thread): polymorphism (was Re: Type checking in python?)
- Next message (by thread): polymorphism (was Re: Type checking in python?)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
"Oivvio Polite" <oivvio at cajal.mbb.ki.se> wrote in message news:8lmo4i$s28$1 at news.kth.se... > For instance I want the constructor to take either a filename, a file object > or a database connection object. ><paul at prescod.net> wrote: >> Let me also point out that in many cases, this style of programming >> would be frowned upon by serious Python programmers. Polymorphism and method overloading aren't really the same thing at all. What Paul was saying was that Python lacks (or doesn't want) a Java like interface concept. So if you wanted a method to be able to write to any stream, you can't specify that in the code. And attempting to enumerate all possible streams would break polymorphism. Python takes the approach that if it looks like a fish and smells like a fish, it probably is a fish. Now what you are doing is rather different. You have three different things: there is nothing that you could say 'filename', 'file object', and 'database connection' are all kinds of. Except 'object' perhaps. How to solve the problem? One approach would be to use a factory style and have three functions: generateXFromFileName(), generateXFromFileObject(), generateXFromDBConn().
- Previous message (by thread): polymorphism (was Re: Type checking in python?)
- Next message (by thread): polymorphism (was Re: Type checking in python?)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list