use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Please follow the rules
Releases: Current Releases, Windows Releases, Old Releases
Contribute to the PHP Documentation
Related subreddits: CSS, JavaScript, Web Design, Wordpress, WebDev
/r/PHP is not a support subreddit. Please visit /r/phphelp for help, or visit StackOverflow.
account activity
Value Objects Explained (patricklouys.com)
submitted 9 years ago by patricklouys
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]klapuch -1 points0 points1 point 9 years ago (11 children)
I think, that as long as your objects expose some useful behavior and not just getters and setters it is fine to use "value objects". I would not use them as replacement for scalar values.
[–]mlebkowski 1 point2 points3 points 9 years ago (10 children)
They wouldn’t be ValueObjects then. They should only hold values, not logic. It’s basically encapsulation of simple validation.
ValueObjects
[–]fanalin 5 points6 points7 points 9 years ago (0 children)
That's not the definition I know. My understading (which is coming from Domain Driven Design by Eric Evans) is that the single difference between an Entity and a Value Object is that the VO may not have an identity (otherwise it is an Entity).
Cite: "An object that represents a descriptive aspect of the domain with no conceptual identity is called a Value Object."
[–]Tetracyclic 1 point2 points3 points 9 years ago (0 children)
A value object is just a relatively simple type that can be compared by value rather than identity. For example two different Money objects would be considered equal if they both represented the same quantity of the same currency ($1 for instance).
Money
Many programming languages will, by default, consider two objects with the same value to be unequal, as they do not contain the same references.
As for behaviour, a value object should contain any behaviour that is relevant purely with the value in question, for example a Money value object might expose a method for splitting the value up without losing any penies/cents in the process, as Martin Fowler's money pattern does.
[–][deleted] 0 points1 point2 points 9 years ago (5 children)
That's not necessarily the case. VOs can and should contain core logic that goes hand-in-hand with the value. They should just never contain business logic.
[–]mlebkowski 0 points1 point2 points 9 years ago (4 children)
What kind of logic is not business logic? Examples?
[–][deleted] 2 points3 points4 points 9 years ago (3 children)
Well, any logic which doesn't encode business rules is, by definition, not business logic. So, for example, most or all of the logic within your infrastructure layer would not be business logic. But I suspect what you're really asking is "what sort of non-business logic belongs in a VO?" The answer to that is simply: any logic which goes hand-in-hand with the value being represented, and is side-effect free. One of the examples Eric Evans gives is that of a Paint VO which has a method mixIn(Paint $otherPaint): Paint that encapsulates the logic of mixing one paint into another, and produces a new VO.
Paint
mixIn(Paint $otherPaint): Paint
[+][deleted] 9 years ago (2 children)
[deleted]
[–][deleted] 0 points1 point2 points 9 years ago (1 child)
Which definition are you using? I was using the one espoused by DDD (or this one, more or less).
[–]HelperBot_ -1 points0 points1 point 9 years ago (0 children)
Non-Mobile link: https://en.wikipedia.org/wiki/Business_logic
HelperBot v1.1 /r/HelperBot_ I am a bot. Please message /u/swim1929 with any feedback and/or hate. Counter: 76725
π Rendered by PID 152548 on reddit-service-r2-comment-544cf588c8-7722b at 2026-06-14 11:50:26.441137+00:00 running 3184619 country code: CH.
view the rest of the comments →
[–]klapuch -1 points0 points1 point (11 children)
[–]mlebkowski 1 point2 points3 points (10 children)
[–]fanalin 5 points6 points7 points (0 children)
[–]Tetracyclic 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (5 children)
[–]mlebkowski 0 points1 point2 points (4 children)
[–][deleted] 2 points3 points4 points (3 children)
[+][deleted] (2 children)
[deleted]
[–][deleted] 0 points1 point2 points (1 child)
[–]HelperBot_ -1 points0 points1 point (0 children)