P.Brian.Mackey
P.Brian.Mackey

Reputation: 44285

OO - Technique for separating objects from instances without introducing bad naming conventions

Often times I need to create an encapsulation to hold an array of an Entity. Let's say we have a class that represents an HTML table.

public class Tables
{
   public Table[] Tables;
   public Tables(){}
}
public class Table
{
   public Header Header;
   public Row Row;
   public Footer Footer;
   public Table(){} 
}

Here, my Tables encapsulate a Collection of Table. I want to call my Table[] Object Tables, but this clashes with my Encapsulation. To me, both represent a table. How should I fix my naming?

Secondly, my Table contains a Footer

//A Special type of Row in a Table
public class Footer: Row
{
}

I could solve this by making my Members lower cased. Although, this goes against Microsoft recommended practices for public members.

I could append a Obj to my Member names...once again, not a good practice. Perhaps I'm viewing my OO encapsulations incorrectly.

Upvotes: 1

Views: 62

Answers (3)

artificialidiot
artificialidiot

Reputation: 5379

Use generics/templates/whatever it is called in your language:

List<Table> ArrayList<Table> Collection<Table>

If you need a custom method on your collection class (i.e. call through this), you are doing it wrong.

Upvotes: 0

N_A
N_A

Reputation: 19897

You should be as descriptive as possible in your naming. What is the feature of your Tables class that requires a new class rather than just an array? If there isn't anything then just use an array, otherwise include the distinctive feature of your class in the name.

Upvotes: 3

Legogris
Legogris

Reputation: 253

"Here, my Tables encapsulate a Collection of Table."

Why not call your class just that - TableCollection?

Upvotes: 1

Related Questions