Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between a class snippet and an object snippet

I would like to know what is the exact difference between a class snippet and an object snippet in lift.

If I have

class Foo {
  var a: String
  def render(n:NodeSeq) = {
    <h3> you chose {a} </h3>
  }
}

and

object Bar {
  var b: String
  def render(n:NodeSeq) = {
    <h3> you chose {b} </h3>
  }
}

What is the concrete difference between them, do a and b have a different behaviour. In simply lift it is said that

In this case, the snippet is an object singleton because it does not take any constructor parameters and has no instance variabled.

So does it mean that for every user, Bar will be the same?

I know that it is a noob question, however I need to be very clear on this and I don't match well the difference between objects and classes in snippets.

like image 819
Christopher Chiche Avatar asked Mar 19 '12 17:03

Christopher Chiche


1 Answers

See this page.

Basically, a new instance of Foo will be created for each http request (so there will be many existing at the same time), but only one instance of Bar will ever exist at the same time.

like image 72
Paolo Falabella Avatar answered Sep 28 '22 10:09

Paolo Falabella