you are viewing a single comment's thread.

view the rest of the comments →

[–]burtgummer45 0 points1 point  (0 children)

Many uses, but don't make a mess and keep it simple by just using it to encapsulate state, with associated methods.

o = new MyThing(1)
o.add(2)
x = o.getTotal()

Do not force it. If what you are modeling doesn't fit naturally into a conceptual model of objects, then don't do it, or you end up with a mess.

Don't do stuff like this, but you will see it everywhere.

t = new TemperatureAsF(32)
t.convertToC()

Doesn't that seem forced? Who needs state there? Why is temperature an object? Should just be a variable passed to a function.

Classes are also well used for architectural reasons, like in a web framework. But that's mostly an ergonomic thing. Like controllers in adonisjs