Expression as Tree — 3. Objects

Expression as Tree is a sequence consisting of the following 5 notional machines:
1. Arithmetic
2. Logic
3. Objects
4. Arrays
5. Comparisons & Conditionals

Programming Language

imperative, OO / Java

Form

Representation

Attribution — Origin / Source

Collected by Matthias Hauswirth — Own practice

Conceptual Advantage

Makes explicit the fact that object allocation, method invocation, and field access are just expressions and can be composed like any other expression.

Mapping

PLNM
... (all aspects from 2-Logic)
null tree node containing 'null'
this tree node containing 'this'
instantiation tree node with 'new', class name, and a parentheses containing comma-separated holes for constructor parameters
variable tree node containing name of variable of an Object type
instance field access tree node containing a hole, a dot, and a field name
instance method invocation tree node with a hole, a dot, and parentheses containing comma-separated holes for method parameters
class field access tree node containing class name, a dot, and a field name
class method invocation tree node with class name, a dot, and parentheses containing comma-separated holes for method parameters

Draws Attention To

The structure, typing, and evaluation of expressions involving instances and classes.

Use When

When explaining nesting and chaining of method calls and constructor calls, class vs. instance method and field accesses, null, and this.

Cost

Small, can be done on paper or with a tool like Expression Tutor.

Details

The following videos and activities come from ExpressionTutor.org, where you can find a much more comprehensive set of resources and tools. Expression Tutor supports many different programming languages, but the material discussed here is specific to Java.

The Crash Course: Expressions in Java provides a learning experience that corresponds to this notional machine sequence.

Explainer Video: Expressions Involving Objects

The following video comes from section Objects of the Crash Course.

Example expressiontutor.org Activity

Here is an example “Expression Tutor” activity. Can you solve it?

Explainer Video: Where to find expressions

Explainer Video: Determining the type of an expression

Explainer Video: Determining the value of an expression

Comments or Feedback?

Do you have feedback on this notional machine? Did you find a mistake, or do you have a request for improvement? You can create an Issue on GitHub, where the description is hosted. This way we can see your feedback and address it.

For this, you need a GitHub account. Then follow this link to see the source file of this page. In there, click the ... left of the highlighted line, then pick "Reference in a new issue".

Create an Issue on GitHub