Moving to an OOP model from an classically imperitive one

MRAB python at mrabarnett.plus.com
Wed Apr 23 19:08:27 EDT 2014


On 2014-04-23 21:57, tim.thelion at gmail.com wrote:
> Hello,
>
> I am currently writting a program called subuser(subuser.org), which
> is written as classically imperative code.  Subuser is, essentially,
> a package manager.  It installs and updates programs from
> repositories.
>
> I have a set of source files
> https://github.com/subuser-security/subuser/tree/master/logic/subuserCommands/subuserlib
> which have functions in them.  Each function does something to a
> program, it identifies the program by the programs name.  For
> example, I have an installProgram function defined as such:
>
> def installProgram(programName, useCache):
>
> Now I've run into a flaw in this model.  There are certain situations
> where a "programName" is not a unique identifier. It is possible for
> two repositories to each have a program with the same name.
> Obviously, I could go through my code and replace all use of the
> string "programName" with a tuple of (programName, repository).  Or I
> could define a new class with two attributes: programName and
> repository, and pass such a simple object arround, or pass a
> dictionary.  However, I think this would be better solved by moving
> fully to an OOP model.  That is, I would have a SubuserProgram class
> which had methods such as "install", "describe", "isInstalled"...
>
[snip]
Could you make the program name unique just by combining it with the
repository name in a single string?



More information about the Python-list mailing list