Typical use case is "call constructor with parameters and then set properties"
On 10/9/07, Guillaume Laforge <
glaforge@...> wrote:
> Is there some reason (use case?) which triggered this idea?
> Frankly, I'm not too fond of mixing maps and parameters too much.
>
> On 10/9/07, Alex Tkachman <
alex.tkachman@...> wrote:
> > Do we want to code like this where constructor params mixed with named
> > properties?
> >
> > class Book {
> > Book (String author, String coauthor) {
> > this.author = author
> > this.coauthor = coauthor
> > }
> >
> > String title, author, coauthor
> > }
> >
> > class SuperBook extends Book {
> > SuperBook (Map map, String author, String coauthor) {
> > super (author, coauthor)
> > title = "SuperBook"
> > }
> > }
> >
> > class NewInstanceTest extends GroovyTestCase{
> > void testNewInstance () {
> > def book = Book.newInstance("Alex", title: "All about it", "Graeme" )
> > assertEquals book.title, "All about it"
> > assertEquals book.author, "Alex"
> > assertEquals book.coauthor, "Graeme"
> > }
> >
> > void testConstructor () {
> > def book = new Book("Alex", title: "All about it", "Graeme" )
> > assertEquals book.title, "All about it"
> > assertEquals book.author, "Alex"
> > assertEquals book.coauthor, "Graeme"
> > }
> >
> > void testSuper () {
> > def book = new SuperBook("Alex", title: "All about it", "Graeme" )
> > assertEquals book.title, "SuperBook"
> > assertEquals book.author, "Alex"
> > assertEquals book.coauthor, "Graeme"
> > }
> > }
> >
> > ---------------------------------------------------------------------
> > To unsubscribe from this list please visit:
> >
> >
http://xircles.codehaus.org/manage_email> >
> >
>
>
> --
> Guillaume Laforge
> Groovy Project Manager
>
http://glaforge.free.fr/blog/groovy>
> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:
>
>
http://xircles.codehaus.org/manage_email>
>
---------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email