AlgoMaster Logo
AlgoMasterDesign Theme Factoryeasy

Design Theme Factory

easy

A settings screen can switch an application between a light theme and a dark theme. A theme is a matching pair: its color palette and its font. If those pieces are created separately, it is easy to end up with a dark palette and a light font after a switch.

The product contracts, all four concrete products, and ThemeManager are already implemented. Your job is to complete only the factory layer:

  • ThemeFactory, the abstract factory contract.
  • LightThemeFactory, which creates the light product family.
  • DarkThemeFactory, which creates the dark product family.

ThemeFactory must provide themeName(), createColor(), and createFont(). Each concrete factory must return its own name and a matching pair of the pre-built products:

Scroll

Factory

createColor()

createFont()

LightThemeFactory

LightColor

LightFont

DarkThemeFactory

DarkColor

DarkFont

Do not reimplement the products or ThemeManager. The tests exercise your factories through this pre-built client:

  • ThemeManager() creates a manager on the light theme.
  • boolean setTheme(String name) switches to "light" or "dark" and returns true. Any other name changes nothing and returns false.
  • String currentTheme() returns the name of the active theme.
  • String colorLine() returns what the active color produces.
  • String fontLine() returns what the active font produces.
  • String partsReport() returns "color=<theme>, font=<theme>", naming the theme that each piece currently in use belongs to.
  • int switchCount() returns how many calls to setTheme were accepted.

The four products produce fixed strings:

  • The light color produces Applying light color: #FFFFFF background, #000000 text.
  • The dark color produces Applying dark color: #1E1E1E background, #FFFFFF text.
  • The light font produces Rendering light theme font: Arial, 14px.
  • The dark font produces Rendering dark theme font: Consolas, 14px.

Theme names are lower case, so "Dark" is not a recognised name. Selecting the theme that is already active still counts as an accepted switch. Although the tests call ThemeManager, the only missing code is the abstract factory and its two implementations.

Example 1:

Input:

Output:

Explanation: A new manager starts on the light theme, so the color, the font and the report all name light.

Example 2:

Input:

Output:

Explanation: One accepted call to setTheme replaces both products, so the color line, the font line and the report move to dark together.

Constraints

  • 0 <= name.length <= 20
  • name contains letters only.
  • At most 100 calls in total are made across all methods.

Starter Code

Only ThemeFactory, LightThemeFactory, and DarkThemeFactory are unfinished. Complete those three types at the marked comments; leave the supplied products and ThemeManager unchanged.

How the design is graded

needs 7/10 to pass
  • Complete abstract factory contract

    Full marks when `ThemeFactory` declares `themeName`, `createColor`, and `createFont` with the expected return types. Lose points when callers must make separate decisions or depend on concrete product types.

  • Consistent concrete families

    Full marks when `LightThemeFactory` returns `light`, `LightColor`, and `LightFont`, while `DarkThemeFactory` returns `dark`, `DarkColor`, and `DarkFont`. Lose points heavily for any mixed family.

  • Focused implementation

    Full marks when only the three requested factory types are added, names and signatures match the scaffold, and methods return objects instead of printing. Lose points for rewriting the supplied products or `ThemeManager`.

Passing every test is not enough on its own. A submission is accepted only when the design also clears the bar.

Hints

Loading...
CallReturns
new ThemeManager()null
currentTheme()"light"
colorLine()"Applying light color: #FFFFFF background, #000000 text"
fontLine()"Rendering light theme font: Arial, 14px"
partsReport()"color=light, font=light"

A new manager starts on the light theme, so the color, the font and the report all name light.

Run checks these cases. Submit also runs a larger hidden set.