From the course: Programming Foundations: Design Patterns
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Challenge: The simple Factory pattern
From the course: Programming Foundations: Design Patterns
Challenge: The simple Factory pattern
(futuristic electronic music) - [Instructor] Take a look at this design. We have a ZoneFactory whose job is to create the right kind of time zone for our calendar app. Let's say you're instantiating a calendar for a user in the Pacific Time Zone. Then you'd ask the ZoneFactory to create the appropriate zone for the calendar to use. The time zones the Factory knows how to create are the U.S. time zones, Eastern Time, Central Time, Mountain Time, and Pacific Time, and each has a corresponding zoneid. The zone displayName is just the name of the time zone, like USPacific, and the offset is the numeric offset of the time zone from GMT which is minus five for Eastern, minus six for Central, minus seven for Mountain, and minus eight for Pacific. Your challenge is to write the code for the Zone classes, that is the Zone class and its subclasses and the ZoneFactory that will create the correct zone based on the zone id…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.