Thursday, September 19, 2013

Play! hates immutables

Ok...
Below the lines ... uh... below... is the original post.
So... it turns out the Play! doesn't hate immutables... The Scala Template engine that Play uses just has a ... way of accessing object fields directly... not through Getters. That made me nervous... requiring all my readable fields to be public makes me nervous. As Joseph mentions below in the comments, you can still use getters and private or protected data... And that seems to be the appropriate Tack...

Good to know...
and thanks Joe.
--------
Trying to wrap my head around Play!'s apparent hatred of using immutable model objects.
Using the scala template engine seems to require public attributes and doesn't seem to care about getters and setters.... hrm... maybe I'm missing something.

Any of you Play Framework workers have anything to say about it?

Maybe i'm over-thinking things...
Yes, probably over-thinking things.

Maybe I could maintain immutables and expose some sort of mutable 'view' that doesn't do anything.

Maybe something like this:

public class Entry {
@Id private String id;
private double latitude;
private double longitude;

        MutableEntry getView(){...}
}

public class MutableEntry {
@Id public String id;
public double latitude;
public double longitude;
}





No comments:

Post a Comment