Creator, Producer, Observer, Or Mutator? - Swarthmore College

Transcription

Creator, producer, observer, or mutator?Creator - create new instances of a type. Creators can take other objects asarguments but not the type itselfProducer - Create new objects from existing objectsObserver - Take instances of a type and return a different typeMutator - Changes an instance

Creator, producer, observer, or mutator?

Creator, producer, observer, or mutator?Producer because it creates a new stringfrom existing strings

Creator, producer, observer, or mutator?

Creator, producer, observer, or mutator?Producer because it creates a new list froman existing list

r,orormutator?mutator?

r,orormutator?mutator?CreatorThis is a special case of constructor whichreturns a constant

r,orormutator?mutator?

r,orormutator?mutator?Mutator because it changes an instance of alist

r,orormutator?mutator?

r,orormutator?mutator?Creator because it creates a new DateTimewhich contains the current time

Creator, producer, observer, or mutator?

Creator, producer, observer, or mutator?Producer because it creates a new stringfrom an existing string

r,orormutator?mutator?

r,orormutator?mutator?Creator because it creates a new Vector3based on a constant

r,orormutator?mutator?

r,orormutator?mutator?Creator because it creates a new DateTimefrom 3 integers (this is a typical creator,invoked with new)

r,orormutator?mutator?

r,orormutator?mutator?Observer because it takes in two Vectors andreturns a boolean; it computes informationthat tells us about left and right. This methodsis called likeVector3 left new Vector3(1,0,0);Vector3 right new Vector3(0,1,0);bool result (left right);

r,orormutator?mutator?

r,orormutator?mutator?Observer because it returns an int given aninstance of DateTime. Hour is a typicalaccessor method implemented as a property.

r,orormutator?mutator?

r,orormutator?mutator?Mutator because it modifies the value ofHours in a DateTime instance

r,orormutator?mutator?

r,orormutator?mutator?Producer because it creates a new Vector3based on existing Vector3

r,orormutator?mutator?

r,orormutator?mutator?Producer because it creates a new DateTimefrom a string. Note this function as two returnvalues: a bool and a result. Note also that it’snot a mutator because it creates a newDateTime rather than modifying the existingone that is passed in. DateTime is animmutable object in .NET

r,orormutator?mutator?

r,orormutator?mutator?Observer because it returns an int based onalist

r,orormutator?mutator?

r,orormutator?mutator?Mutator because it modifies an existing list

Creator, producer, observer, or mutator?Creator, producer, observer, or mutator? Producer because it creates a new DateTime from a string. Note this function as two return values: a bool and a result. Note also that it's not a mutator because it creates a new DateTime rather than modifying the existing one that is passed in. DateTime is an