Designing Win Zip Utility

WinZip Application Design

Another example of this pattern is your WinZip utility. Your WinZip utility doesn’t recognize different files, folders or subfolders separately. If you want to zip a file, you can call the same zip method whether it is a file, subfolder or a top level folder.

The whole part structure out here is the file structure where folder is a whole and file is the part.

Now your WinZip application doesn’t need to understand the difference between a folder and a file. So you make both of them implement the zippable interface which has a method called compress().

Figure- Figure

As shown in the figure, there is an interface called as ZippableItem with a method compress(). There is a Class File which represents a discrete File in the file system while there is a class Folder which is a collection of ZippableItems. As File and Folder are implementing the same interface ZippableItem they are forced to override the compress() method. The compress() of the File has to logic of compressing a different types of individual files. As Folder is a collection of ZippableItems, the logic of the compress() of the Folder is to iterate through all the ZippableItems in collection and call the compress() method on the same.

 
Hemant Jha
Founder - VPlanSolutions
Researcher, Trainer

www.VPlanSolutions.co.in