Alex Rivera | Logout

Class vs data structure

Asked 2010-11-22T05:46:23.873
29

In object oriented programming, a custom class (like Person class with data of Name, list of addresses, etc)holds data and can include collection objects too. A data structure is also used to hold data too. So, is a class considered advanced data structure conceptually ? And in design of efficient systems (in object oriented world and large systems), are classes considered as similar to data structures and algorithmic analysis done for efficient classes designs for greater efficiency(in companies like google, facebook) ?

Edit
Report

1 Answer

5

A class is simply a collection of data and methods which can act on that data. You can use a class to implement a data structure, but they are different things.

Take the Linked List for example. You can implement a Linked List data structure using a class, and in some languages this is the cleanest and most obvious way of doing it. It is not the only way to implement a Linked List, but it might be the best depending on the language.

A Linked List however, has nothing to do with being a class. A Linked List is instead a way of representing data as separate nodes where each node is linked to the next in some fashion.

A data structure is a conceptual way of modeling data, each different data structure having different properties and use cases. A class is a syntactic way that some languages offer to group data and methods.

Classes often lend themselves to being used to implement data structures, but it would be incorrect to say that a class == a data structure.

answered 2010-11-22T05:59:43.027

Your Answer