473,403 Members | 2,359 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Single Class vs. Multiple Classes

While developing an internal IE6-only webapp, a discussion started about the
'best' way to apply classes to data tables across multiple pages. The two
arguments were:

1. Apply a single class to each table. That class (possibly in combination
with other classes on child elements) controls every part of the table -
layout, colors, fonts, etc. Example: class="data"

PROS: Easier to standardize, less specificity confusion, everything is
self-contained

CONS: Each slightly different table variation needs an entirely new class,
different classes may have many rules in common

2. Apply multiple classes to each table. Possibly one for layout, one for
colors, one for effects, etc. Example: class="compact dark grid dropshadow"

PROS: Classes control one aspect of table and combine in many different
ways, class rules don't grow too big or overlap

CONS: Possible specificity collisions, style selections seems to move into
html rather than in css, confusing to know which classes to pick

So this is mostly a question of opinion - When do you suggest using one
class vs. multiple classes and why? Is there a general rule that can be
quantified, or does it depend on the situation?

Some discussion on the question would be great!

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
May 2 '06 #1
4 4664
Matt Kruse wrote:
While developing an internal IE6-only webapp, a discussion started about the
'best' way to apply classes to data tables across multiple pages. The two
arguments were:

1. Apply a single class to each table. That class (possibly in combination
with other classes on child elements) controls every part of the table -
layout, colors, fonts, etc. Example: class="data"

PROS: Easier to standardize, less specificity confusion, everything is
self-contained

CONS: Each slightly different table variation needs an entirely new class,
different classes may have many rules in common


Ask yourself: Are the tables conceptually different so that the
presentation should be different? If yes, create a new class.

Then use something like

.schedule, .sales, .scores {
/* common properties */
}

to make your life easier.
--
Johannes Koch
Spem in alium nunquam habui praeter in te, Deus Israel.
(Thomas Tallis, 40-part motet)
May 2 '06 #2
Matt Kruse wrote:
While developing an internal IE6-only webapp, a discussion started about the
'best' way to apply classes to data tables across multiple pages. The two
arguments were:

1. Apply a single class to each table. That class (possibly in combination
with other classes on child elements) controls every part of the table -
layout, colors, fonts, etc. Example: class="data"

2. Apply multiple classes to each table. Possibly one for layout, one for
colors, one for effects, etc. Example: class="compact dark grid dropshadow"

So this is mostly a question of opinion - When do you suggest using one
class vs. multiple classes and why? Is there a general rule that can be
quantified, or does it depend on the situation?

This is a similar to a topic that goes around in object-oriented
programming circles (e.g. C++): single inheritance vs. multiple
inheritance. It is stretching it a bit to say it is the same as single
class vs. multiple classes, but not far off either.
The general consensus is that multiple inheritance is to be avoided; the
word "evil" often arose in discussions. It creates non-linear relations
that are hard to track as the code ages, specifically the "unintended
consequences" problem, aka: collateral damage, ripple effect,
interdependence, high cohesion.
Multiple inheritance does not scale well and is hard to maintain. The
same can be said for multiple classes. Building a bunch of Lego styles may
seem efficient at first. It becomes a mess after a while.
Consider what happens when you change the ruleset for "dropshadow."
Wherever dropshadow is used, its appearance changes. When used in multiple
class style, zero or more unrelated parts of the site change appearance as
well. This may or may not be desirable.
Multiple classes can be useful when used in a focused, limited manner.
It is not a generally useful method.

--
jmm (hyphen) list (at) sohnen-moe (dot) com
(Remove .AXSPAMGN for email)
May 3 '06 #3

Jim Moe wrote:
This is a similar to a topic that goes around in object-oriented
programming circles (e.g. C++): single inheritance vs. multiple
inheritance.


Dangerous approach for CSS though. CSS does cascading, not inheritance
and OO programmers have historically found themselves getting very
confused by this difference.

May 3 '06 #4
di*****@codesmiths.com wrote:
This is a similar to a topic that goes around in object-oriented
programming circles (e.g. C++): single inheritance vs. multiple
inheritance.


Dangerous approach for CSS though. CSS does cascading, not inheritance
and OO programmers have historically found themselves getting very
confused by this difference.

Ah, I was unclear, then. I did not mean cascading at all, only the use
of multiple classes.

--
jmm (hyphen) list (at) sohnen-moe (dot) com
(Remove .AXSPAMGN for email)
May 3 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Aguilar, James | last post by:
I know that one can define an essentially unlimited number of classes in a file. And one can declare just as many in a header file. However, the question I have is, should I? Suppose that, to...
7
by: jsale | last post by:
I have made an ASP.NET web application that connects to SQL Server, reading and writing data using classes. I was recommended to use session objects to store the data per user, because each user...
2
by: Howard Postley | last post by:
This seems like it's probably a pretty basic question but is there a way to publish multiple classes from a single web service URL? Using VS.NET, I create a project, FOO and add a web service,...
4
by: vze1r2ht | last post by:
I have many types of classes and I'm deciding whether to use a single class or multiple classes for EACH type of class. For an example: User class has 3 classes associated with it: User...
6
by: Ole Nielsby | last post by:
I'm having a strange problem with sealing virtual indexers. Looks like a compiler error to me - or have I overlooked some obscure statement in the specs? I have two virtual indexers in the...
3
by: Claudio Pacciarini | last post by:
Hi everyone, I have a question about .NET code sharing and reuse, and also about application design best practices / guidelines. Currently, we have many different .NET projects in source...
6
by: Orgun | last post by:
Hi, I sent this message to the moderated c++ group too but it is waiting for moderator approval and I wanted to send here too. I am new to Design Patterns. I want to write a simple...
1
by: =?Utf-8?B?UEI=?= | last post by:
Hi I was investigating whether we could have a single entry-point (.asmx) to multiple Web Service classes instead of just one. Something like: <%@ WebService Language="C#" Class="Class1"...
4
by: Alan Mailer | last post by:
Again, I'm new to VB.net and there is something I need help with: Like (I assume) many of us, over time I want to be able to create some VB.net classes that I might want to use in more than one...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.