devxlogo

Use Multiple Object Types to Reduce Duplicate Code

Use Multiple Object Types to Reduce Duplicate Code

In the “Determine the Class of YourObject with the TypeOfStatement” tip, the Desk and House objects have many propertiesin common. Instead of duplicating code by having a separate Printmethod for each object, we can write a generic routine to handleprinting of each object type. Note that the advantage of thisimplementation rises as the number of object types and/or thenumber of similarities between object types increases.

devx-admin

Share the Post: