Dec. 9th, 2010

juan_gandhi: (Default)
object closable {
  type Closable = { def close }
  class Autoclose[A <: Closable](c: A){
    def foreach(f: A => Unit) = {
      try { f(c) }finally { c.close }
    }
  }
  implicit def autoClosable[A <: Closable](c: A) = new Autoclose(c)
//...
  case class Connection(name:String) {
    def close = println("closing " + this) 
  }
  case class Statement(c: Connection,q :String){
    def close = println("closing " + this)
    def exec = println("executing " + q + " on " + c)
  }
  def test = for(c <- Connection("conn"); 
		 st <- Statement(c,"select * from table")){
		   st.exec
		 }
}


[livejournal.com profile] _navi_, I remember you were talking about something like this

(src 10x Ramzi ben Yahia).
juan_gandhi: (Default)
... and/or strategies.

I was pondering where do I stick my two factory strategies, or rather strategy factories - wrote an abstract class and thought about having two final static members, with well-named implementations, when it occurred to me - kaboom, it's an enum:
enum GadgetFactory {
  christmasGadget {
    Gadget build(User user, WeakReference<Something>) {
      ...
   },
  newYearGadget {
    Gadget build(User user, WeakReference<Something>) {
      ...
   };

   abstract Gadget build(User user, WeakReference<Something>);
}


Sure it is obvious. But if it is, why people hardly ever do it this way?
juan_gandhi: (Default)
В презентацию анимированные гифы вставлять?

Profile

juan_gandhi: (Default)
Juan-Carlos Gandhi

August 2025

S M T W T F S
      12
3456789
10 11 12 13141516
171819 20212223
24252627282930
31      

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Aug. 24th, 2025 09:24 am
Powered by Dreamwidth Studios