-1

Is there a design pattern that represents Sprite's use of the Graphics class, are there any pro's & con's to this behavior.

AS3docs on Sprite.graphics

Community
  • 1
  • 1
redlamp
  • 101
  • 6
  • `graphics` is a property, not a class. – Ry- Oct 03 '14 at 22:28
  • "graphics" is a property of Sprite, that property is an instance of the "Graphics" class. – redlamp Oct 03 '14 at 22:30
  • What are you trying to ask here? – xxbbcc Oct 03 '14 at 22:31
  • Yes, it is, so `Sprite` doesn’t “encapsulate” the `Graphics` class just by virtue of having a property that’s an instance of `Graphics` (and that’s not what encapsulation is anyways). – Ry- Oct 03 '14 at 22:32
  • Sprite's use of Graphics isn't a Decorator pattern, I'm curious if there is a design pattern name for this type of behavior. – redlamp Oct 03 '14 at 22:32

1 Answers1

1

That design pattern is called object composition and is one of the basic patterns of object oriented programming (OOP) along with object inheritance (also called subtyping).

For the pros and cons, it depends on the implementation alternatives you have. Wikipedia has an article on Composition over inheritance. You might also be interested by this question : What are some best object-oriented design practices?

@minitech Sprite.graphics is a property of the type Graphics which is a class.

Community
  • 1
  • 1
Daishi
  • 12,681
  • 1
  • 19
  • 22