Remaining nimble in the face of evolution

Pete Shinners pete at shinners.org
Wed Feb 6 11:19:31 EST 2002


jim.vickroy wrote:
> Now a reality check occurs and the requirement evolves such that the
> archival behavior is to be optional.
> 
> What is the "best" strategy to handle these types of evolution.

first thing that jumps to my mind, use the "getattr" / "hasattr" 
functions to determine if the objects have the 'archiving' methods you need.

if hasattr(myinstance, "archive_method"):
	myinstance.archive_method(file_or_something)


this should work pretty well for you. now you can define new classes 
which don't have the "archive_method". if all your classes are inherited 
from a base class that _does_ have the archive _method, perhaps you can 
just set that method to "None" for the classes that should not be written.


class new_nonsavable(master_base_class):
	archive_method = None

now you can just check if archive_method is a true value and call it

if myinstance.archive_method:
	myinstance.archive_method(file_or_something)




More information about the Python-list mailing list