Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Object Oriented CSS: Catchy Buzz-phrase or Legitimate Design Approach?

It seems there is a new catch-phrase emerging in the web development field: object-oriented CSS.

On the face of it, this strikes me as simply being best-practice packaged up in a catchy slogan. I understand and fully respect the intentions behind the movement, but is there any more to it?

Does anyone have any further insight that sets this approach apart as something more credible or should I just take it as a reminder to make sure I inherit and cascade my classes correctly?

like image 216
Phil.Wheeler Avatar asked Mar 18 '09 08:03

Phil.Wheeler


1 Answers

I would say it's more of a catchy buzz-phrase for something already present in CSS. Of course, before we start talking about what is OO and what is not and how CSS is object-oriented, we would have to define what it actually is - which is something others have struggled with before and is subject to heated debates. But if we assume that the basic principles of OO are:

  • Class
  • Object
  • Instance
  • Method
  • Message passing
  • Inheritance
  • Abstraction
  • Encapsulation
  • Polymorphism
  • Decoupling

we can say, that Cascading Style Sheets are somewhat object-oriented, because they allow classes to be defined, instances/objects created (by assigning a class to an element), inheritance of classes (even multiple inheritance), abstraction (e.g. by defining styles for the plain elements) and polymorphism (by defining the same class name for different elements). Of course methods/message passing is not possible, because of the static nature of CSS.

So in general I would say its a valid approach to develop CSS in an object-oriented manner, but I would not really call it Object Oriented CSS, because at least to me, it is something deeply inherent to CSS. It would be somewhat like saying "I am doing Object Oriented Java..."

like image 150
Simon Lehmann Avatar answered Sep 20 '22 15:09

Simon Lehmann