开发者

Abstract Syntax tree vs Object Model

What is the difference between an object model and an Abstract syntax tree?

I have a confusion with these terms. What I know about these开发者_运维技巧 are

  1. An object model gives details of objects and their relationship in an Application.

  2. AST will give the structure of the program elements of an application.

What can we obtain from object model that cant be obtained from the AST?

Thanks in Advance.


An Object Model and AST are representing things at different levels of abstraction, they have very little in common other than diagrams of each may contain lines, boxes and text.

The Wikipedia example of an AST shows tree representing the result of parsing of a small snippet of a programming language.

An Object model is one of a number of descriptions of an OO design where we are thinking about objects of various classes. When we think about objects we want to know what they do and what they "know". So if we have, say a Customer object C, some orders C has placed O1 and O2 and some products P1, P2, P3 referenced by those orders, we could diagram the relationships, and start to reason about what might happen in particular business scenarios - for example suppose O2 is an order for { P2 and P3 } we can think about how we might work out the price for the order, or what we might do if we are out of stock for P3.

The AST for even a single class would be quite extensive and very hard to understand in terms of behaviour. I don't believe that you could reason about those business scenarios from an AST.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜