lecture13_composite.pdf - CSC3380 Object Oriented Design Lecture 13 Composite Survey for Juniors/Seniors • DXC is interested in your skills/interest

lecture13_composite.pdf - CSC3380 Object Oriented Design...

This preview shows page 1 - 9 out of 21 pages.

CSC3380 Object Oriented Design Lecture 13: Composite
Image of page 1
Survey for Juniors/Seniors DXC is interested in your skills/interest They may reach out Complete this survey: 0494371440153
Image of page 2
The composite pattern Allows tree structures to be represented in code Page 353 of Head First, Page 163 of GoF Happens whenever a tree can contain either a: Leaf node Another tree
Image of page 3
GoF structure Image source: - composite-and-visitor-pattern/
Image of page 4
Simple example: Tree View
Image of page 5
What do tree view elements look like? draw() is implemented by both leaves and groups Add/remove is an error for leaves (this may be bad)
Image of page 6
Code for TreeElem //Note: we’re omitting “parent”, //but it’s allowed public abstract class TreeElem { private Graphic icon; public abstract void draw(); public abstract void add( TreeElem child ); public abstract void remove(TreeElem chld); public abstract TreeElem getChild( int ); public TreeElem( Graphic icon ) { this.icon = icon; } }
Image of page 7
Leaf is easy
Image of page 8
Image of page 9

You've reached the end of your free preview.

Want to read all 21 pages?

  • Spring '09
  • Suptik

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes
A+ icon
Ask Expert Tutors