Understanding Composite Patterns in Binary Expressions and Abstract Classes
This text explores the concept of composite patterns in programming, focusing on binary expressions. It discusses how leaf and non-leaf nodes share the same interface, enabling a unified treatment of parts and wholes. The hierarchical structure allows for simple interfaces that facilitate control propagation throughout systems. Additionally, it delves into the nature of abstract base classes like Expression and BinaryExp, examining their design, evaluation processes, and the distinction between constants and variables in production grammar like RSG. Gain insights into their definitions and practical applications.
Understanding Composite Patterns in Binary Expressions and Abstract Classes
E N D
Presentation Transcript
Assign BinaryExp Add Expression Constant Variable 2 Composite Pattern: Expressions • Leaf and non-Leaf (part/whole) have same interface • Treat whole like part • How are parts added to a whole? • Simple interface, control propagates through system • Expression and BinaryExp are abstract base classes • What makes a class abstract? • Why are abstract classes designed? • How is a BinaryExp class evaluated? • What about a Constant? Variable?
Production GrammarElement Terminal Nonterminal Definition RSG Composite • What’s in a Production? • What’s in a Definition? • What’s in a Nonterminal? * *