Skip to content

Objects Prefer Immutability #1

@mpmenne

Description

@mpmenne

Hey Scott,

Code looks great. One of the only things I found to consider cleaning up is the getter and setter for the pyramid on the pyramid printer interface. Typically interfaces do not contain getters and setters.

The reason is that objects prefer to be immutable. If we eliminate the setter then we can be sure that the Printer object can never change... it will always give us consistent results.

The way to fix this is that we can pass the Pyramid object in through the constructor or pass the Pyramid object in through the method call itself. Anything that the Printer inherently needs to operate we pass in through the constructor (or Spring). Since FilePrinter and the ScreenPrinter are Spring injected "singletons" we could also just pass the pyramid in through the print method call.

In doing so it gives you more flexibility to the things that the Printer and in the long run makes the code better.

Cheers,
Mike

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions