Thursday, July 17, 2008

Comments on Comments on the Previous post

  • Henry Ware suggested a modification to the builder with abstract members removing a lot of the boilerplate. Incidentally, this is a nice illustration of how nested types can be put to a good use in Scala.
  • Justin ported the code to Haskell, which was very cool.
  • A couple of commenters suggested that languages with support for default parameter values (like Python and Groovy) don't need elaborate constructs such as the builder pattern. There are two ways to respond. One is to remind that the intent of the pattern, specially as originally described in the GoF book, has little to do with optional data. The other is to acknowledge that I probably put too much emphasis on this issue and forgot to mention a very common idiom for building objects in Scala: just declare mandatory "parameters" as abstract vals and optional ones as concrete vals with default values, like so:
    abstract class OrderOfScotch {
    val brand:String
    val mode:Preparation
    val isDouble:Boolean
    val glass:Option[Glass] = None
    }

    And to instantiate:
    val myDose = new OrderOfScotch {val brand = "Bobby Runner"; val mode = OnTheRocks; val isDouble = false}
  • I guess that's it. Thanks y'all.

6 comments:

meiko said...

The class "OrderOfScotch" has to be abstract - or a Trait, because there are abstract members...
(trait OrderOfScotch {/*...*/})

Rafael de F. Ferreira said...

You're right meiko, thanks. I'll update the post to correct the mistake.

Omni Verma said...

Papers pf Cbse 10th 12th
Cbse 10th 12th papers
Cbse 10th 12th Quesiton papers
Msbte time Table and Quesiton Paper
Msbte time Table and Quesiton Paper Download
Msbte time and Previous Quesiton Paper
Download Msbte time and Quesiton Papers
Msbte time and Msbte Quesiton Paper
Msbte time Table and Msbte Quesiton Paper

Unknown said...

Please refer below if you are looking for best Online job support and proxy interview from India

DevOps Proxy Interview Support From India | PHP Proxy Interview Support From India | Selenium Proxy Interview Support From India | Hadoop Proxy Interview Support From India | Java Proxy Interview Support From India | Angular Proxy Interview Support From India | Python Proxy Interview Support From India | Android Proxy Interview Support From India

Thank you for excellent article.

mahi said...

Please refer below if you are looking for best Training center in coimbatore

Java Training in Coimbatore | Digital Marketing Training in Coimbatore | SEO Training in Coimbatore | Tally Training in Coimbatore | Python Training In Coimbatore | PMP Training In Coimbatore | Scrum Training In Coimbatore

Thank you for excellent article.

Naveen said...

Please refer below if you are looking for best Training in coimbatore

Hadoop Training in Coimbatore | CCNA Training in Coimbatore | AWS Training in Coimbatore | AngularJS Training in Coimbatore | Dotnet Training In Coimbatore | SAS Training In Coimbatore | R-Programming Training In Coimbatore

Thank you for excellent article.