« Return to Thread: constructors with mix of params and Map

Re: constructors with mix of params and Map

by Alexandru Popescu ☀ :: Rate this Message:

Reply to Author | View in Thread

If we are looking for such features, I think Python system is the best
approach, and we should invent something in this field (it is usually
not allowed to mix location bound parameters with named parameters).

./alex
--
.w( the_mindstorm )p.


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
>
>

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

 « Return to Thread: constructors with mix of params and Map