obje c ts of va lue
play

Obje c ts of Va lue Ke vlin He nne y ke vlin@c ur br alan.c om - PowerPoint PPT Presentation

Obje c ts of Va lue Ke vlin He nne y ke vlin@c ur br alan.c om @Ke vlinHe nne y See http://programmer.97things.oreilly.com (also http://tr.im/97tepsk and http://tinyurl.com/97tepsk ) and follow @97TEPSK What Do We Mean by Value ? T he te


  1. Obje c ts of Va lue Ke vlin He nne y ke vlin@c ur br alan.c om @Ke vlinHe nne y

  2. See http://programmer.97things.oreilly.com (also http://tr.im/97tepsk and http://tinyurl.com/97tepsk ) and follow @97TEPSK

  3. What Do We Mean by Value ? � T he te rm value is use d in ma ny ove rla pping a nd c ontra dic tory wa ys � T he me c ha nism of pass by value � A de c la ra tive c onstruc t, e .g ., C# str uc t s de fine prog ra mma tic value type s � A kind of obje c t re pre se nting fine - g ra ine d informa tion in a doma in mode l � T he g e ne ra l notion of qua ntity or me a sure of some thing in the re a l world

  4. Many objects have no conceptual identity. These objects describe some characteristic of a thing. [...] When you care only about the attributes of an element of the model, classify it as a VALUE OBJECT . Make it express the meaning of the attributes it conveys and give it related functionality. Treat the VALUE OBJECT as immutable. Don't give it any identity and avoid the design complexities necessary to maintain ENTITIES .

  5. Complementary Perspectives � T he Pla tonic Pe rspe c tive � An ide a lise d vie w of wha t va lue s a re in te rms of ma ths a nd the physic a l world � T he Computa tiona l Pe rspe c tive � A mode l- ba se d vie w of wha t va lue s a re in te rms of prog ra mming c onc e pts � T he L a ng ua g e Pe rspe c tive � T he c omputa tiona l vie w bound to the spe c ific s of a prog ra mming la ng ua g e

  6. phenomenon (plural: phenomena): An element of what we can observe in the world. Phenomena may be individuals or relations . Individuals are entities , events , or values . Relations are roles , states , or truths . individual: An individual is a phenomenon that can be named and is distinct from every other individual: for example, the number 17, George III, or Deep Blue's first move against Kasparov. relationship: A kind of phenomenon . An association among two or more individuals , for example, Mother(Lucy, Joe) . Also, generally, any pattern or structure among phenomena of a domain .

  7. Events. An event is an individual happening, taking place at some particular point in time. Each event is indivisible and instantaneous . Entities. An entity is an individual that persists over time and can change its properties and states from one point in time to another. Values. A value is an intangible individual that exists outside time and space, and is not subject to change. States. A state is a relation among individual entities and values; it can change over time. Truths. A truth is a relation among individuals that cannot possibly change over time. Roles. A role is a relation between an event and individuals that participate in it in a particular way.

  8. On the Origin of Species � Va lue type s diffe r in the g e ne ra lity a nd foc us of the ir doma in � Some a re ma the ma tic a l, e .g ., inte g e rs � Some a re prog ra mma tic , e .g ., string s � Some a re re a l world, e .g ., ISBNs � Va lue type s re fle c t c onstra ints � E .g ., ISBNs ha ve a we ll- forme dne ss rule � E .g ., int is a bounde d subse t of inte g e rs

  9. Systems of Values � Ope ra tions, re la tionships a nd c onstra ints form syste ms of va lue s � E .g ., a point in time is a va lue , a s is the diffe re nc e be twe e n two points in time , but time point , time pe r iod a nd time inte r val a re not e quiva le nt type s � E .g ., dista nc e divide d by time yie lds spe e d (a nd displa c e me nt divide d by time yie lds ve loc ity)

  10. povo, sm . 1. Conjunto de indivíduos que falam (em regra) a mesma lingua, têm costumes e hábitos idênticos, uma história e tradições communs. 2. Os habitantes duma localidade ou região; povoação. 3. V. povoado . 4. Multidão . 5. V. plebe . Minidicionário da Língua Portuguesa

  11. Whole Value Whole Value Besides using the handful of literal values offered by the language (numbers, strings, true and false) and an even smaller complement of objects normally used as values (date, time, point), you will make and use new objects with this pattern that represent the meaningful quantities of your business. These values will carry whole, useful chunks of information from the user interface to the domain model. Construct specialized values to quantify your domain model and use these values as the arguments of their messages and as the units of input and output. Make sure these objects capture the whole quantity, with all its implications beyond merely magnitude; but keep them independent of any particular domain. (The word value here implies that these objects do not have identity of importance.) Ward Cunningham "The CHECKS Pattern Language of Information Integrity"

  12. Values as Objects � F rom a prog ra mming pe rspe c tive , we c a n mode l va lue s a s obje c ts � He nc e value obje c ts a nd value type s � Va lue obje c ts ha ve sig nific a nt sta te but insig nific a nt ide ntity � But the re is no dic hotomy or c onflic t be twe e n value s a nd obje c ts � A value obje c t is a kind or style of obje c t tha t re a lise s a value

  13. Patterns of Value V AL UE O BJE CT O PE RAT ORS C E L L F OL L OW V AL UE B UIL - INS T C OPIE D I MMUT ABL E O VE OAD – RL V AL UE V AL UE O VE RRIDE C L ASS M E HOD P AIR T F M E ACT ORY ANINGF UL M E C ONST T HOD RUCT ION C L ONING M UT ABL E B RIDGE C OMPANION C ONVE RSION M E T HOD M E T HOD C OPY C ONST RUCT OR V AL IDAT ING I MPL ICIT C ONST RUCT OR T YPE - S PE W IDE CIF IC NING O VE C ONVE RL OAD RSION

  14. Identity Behaviour State

  15. Ref efer erential tr ential transpar ansparenc ency and ref efer erential opaqueness ential opaqueness are properties of parts of computer programs. An expression is said to be referentially transparent if it can be replaced with its value without changing the program (in other words, yielding a program that has the same effects and output on the same input). The opposite term is referentially opaque. While in mathematics all function applications are referentially transparent, in programming this is not always the case. The importance of referential transparency is that it allows a programmer (or compiler) to reason about program behavior. This can help in proving correctness, simplifying an algorithm, assisting in modifying code without breaking it, or optimizing code by means of memoization, common subexpression elimination or parallelization. http://en.wik http://en.wikipedia.or pedia.org/wik g/wiki/R /Ref efer eren ential_tr tial_transpar nsparenc ncy_(computer_science) y_(computer_science)

  16. Immutable Value Define a value object type whose instances are immutable. Copied Value Define a value object type whose instances are copyable.

  17. General POLO Anatomy � Construc tion... � Construc tor re sults in va lid obje c t � Compa rison... � E qua lity is a funda me nta l c onc e pt � T ota l orde ring ma y or ma y not a pply � Cla ssific a tion a nd c onve rsion... � Ne ithe r a subc la ss nor a supe rc la ss be � Ma y support c onve rsions

  18. Value Object Smells � Ana e mia � L ittle be ha viour be yond fie ld a c c e ss � Role c re e p � Unc ohe sive , e xte rna l de pe nde nc ie s, ... � Inc omple te or surprising c ompa rison � E qua lity ba se d on one a ttribute only � Unwa nte d a fforda nc e s � Non- me a ning ful a nd we a k c onstruc tor

  19. public final class Date implements ... { ... public int getYear() ... public int getMonth() ... public int getDayInMonth() ... public void setYear(int newYear) ... public void setMonth(int newMonth) ... public void setDayInMonth(int newDayInMonth) ... ... }

  20. public final class Date implements ... { ... public int getYear() ... public int getMonth() ... public int getWeekInYear() ... public int getDayInYear() ... public int getDayInMonth() ... public int getDayInWeek() ... public void setYear(int newYear) ... public void setMonth(int newMonth) ... public void setWeekInYear(int newWeek) ... public void setDayInYear(int newDayInYear) ... public void setDayInMonth(int newDayInMonth) ... public void setDayInWeek(int newDayInWeek) ... ... }

  21. public final class Date implements ... { ... public int getYear() ... public int getMonth() ... public int getWeekInYear() ... public int getDayInYear() ... public int getDayInMonth() ... public int getDayInWeek() ... public void setYear(int newYear) ... public void setMonth(int newMonth) ... public void setWeekInYear(int newWeek) ... public void setDayInYear(int newDayInYear) ... public void setDayInMonth(int newDayInMonth) ... public void setDayInWeek(int newDayInWeek) ... ... private int year, month, dayInMonth; }

  22. public final class Date implements ... { ... public int getYear() ... public int getMonth() ... public int getWeekInYear() ... public int getDayInYear() ... public int getDayInMonth() ... public int getDayInWeek() ... public void setYear(int newYear) ... public void setMonth(int newMonth) ... public void setWeekInYear(int newWeek) ... public void setDayInYear(int newDayInYear) ... public void setDayInMonth(int newDayInMonth) ... public void setDayInWeek(int newDayInWeek) ... ... private int daysSinceEpoch; }

  23. When it is not necessary to change, When it is not necessary to change, it is necessary not to change. it is necessary not to change. Lucius Cary

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend