What is the difference between the shape and structure of an object?

I see it used a lot in data context. From ScottGu post :

One of the really powerful features that LINQ and query syntax provides is the ability for you to define new classes that are separate from the requested data and then use them to manipulate the form and structure of the returned data upon request.

What does he mean when he refers to the data form?

0


a source to share


4 answers


consider the form as an "api" object and structure is an internal implementation. In a well-designed system, the form will remain stationary, while the structure can change significantly.



+1


a source


I think these are informal terms and the definitions are subjective. I would use "shape" to refer to how an object fits into other objects in the system. (Compare "surface area", which is a rough (no pun intended :-) measure of the complexity of an object's interface.) I would use "structure" to refer to how the object is internally designed and implemented.



Therefore, you can have classes that have good "shape" but structure like crepe paper. This is probably easier to refactor than the other way around: bad shape, but good implementation. (I'm sure some people will ask if the latter is possible.)

+3


a source


Shape represents any spatial attributes (especially as defined by the outline) of an object, whereas structure is the way an object is constructed and its parts are arranged. This can of course apply to any type of object. :)

+1


a source


Generally, I consider the form of class a as public methods and properties offered by the class. The structure will be internal designs and performance. In the context of the material being quoted, I would like to say that by allowing you to define the return type of a query using anonymous or alternative named classes, you can override the data returned by the query by holding back and transforming its form from the original data source.

For example, let's say you have a users table associated with a contacts table. By using LINQ and anonymous class as a choice, you can return the user with the main contact object without having to define a specific view; using only LINQ.

var userWithContact = from u in db.Users
                      select new
                          { 
                            Name = u.Name,
                            Address = u.Contacts
                                       .Where( c => c.Type = "self" ).First().Address
                          };

      

+1


a source







All Articles