JavaScript Domain Driven Design Speed up your application development by leveraging the patterns of domain driven design 1st Edition Philipp Fehre 2024 Scribd Download
JavaScript Domain Driven Design Speed up your application development by leveraging the patterns of domain driven design 1st Edition Philipp Fehre 2024 Scribd Download
com
https://ebookmeta.com/product/javascript-domain-driven-
design-speed-up-your-application-development-by-leveraging-
the-patterns-of-domain-driven-design-1st-edition-philipp-
fehre/
OR CLICK HERE
DOWLOAD NOW
ebookmeta.com
https://ebookmeta.com/product/deconstructing-doctoral-discourses-
stories-and-strategies-for-success-1st-edition-deborah-l-mulligan/
ebookmeta.com
The Vampire s Choice Victoria Blisse
https://ebookmeta.com/product/the-vampire-s-choice-victoria-blisse/
ebookmeta.com
https://ebookmeta.com/product/aesthetic-action-1st-edition-klinger/
ebookmeta.com
https://ebookmeta.com/product/rabbit-biotechnology-rabbit-genomics-
transgenesis-cloning-and-models-louis-marie-houdebine-jianglin-fan/
ebookmeta.com
https://ebookmeta.com/product/metaheuristics-for-resource-deployment-
under-uncertainty-in-complex-systems-1st-edition-shuxin-ding/
ebookmeta.com
What Next How to Get the Best From Brexit 1st Edition
Daniel Hannan
https://ebookmeta.com/product/what-next-how-to-get-the-best-from-
brexit-1st-edition-daniel-hannan/
ebookmeta.com
The Sale of Goods 4th Edition M. G. Bridge
https://ebookmeta.com/product/the-sale-of-goods-4th-edition-m-g-
bridge/
ebookmeta.com
www.it-ebooks.info
JavaScript Domain-Driven
Design
Philipp Fehre
BIRMINGHAM - MUMBAI
www.it-ebooks.info
JavaScript Domain-Driven Design
All rights reserved. No part of this book may be reproduced, stored in a retrieval
system, or transmitted in any form or by any means, without the prior written
permission of the publisher, except in the case of brief quotations embedded in
critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy
of the information presented. However, the information contained in this book is
sold without warranty, either express or implied. Neither the author, nor Packt
Publishing, and its dealers and distributors will be held liable for any damages
caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the
companies and products mentioned in this book by the appropriate use of capitals.
However, Packt Publishing cannot guarantee the accuracy of this information.
ISBN 978-1-78439-432-5
www.packtpub.com
www.it-ebooks.info
Credits
Reviewers Proofreader
Vahagn Grigoryan Safis Editing
Max Kirchoff
Michael Smith Indexer
Tejal Soni
Commissioning Editor
Taron Pereira Graphics
Jason Monteiro
Acquisition Editors
Sonali Vernekar Production Coordinator
Melwyn D'sa
Greg Wild
Cover Work
Content Development Editor
Melwyn D'sa
Rohit Kumar Singh
Technical Editor
Rohith Rajan
Copy Editors
Charlotte Carneiro
Ameesha Smith-Green
www.it-ebooks.info
About the Author
For years, he has been fascinated by the possibilities of JavaScript and followed
Node.js from its beginnings, using it for research projects and production
web services.
I'd like to thank my wife, Steffi, for her continuous support and for
dealing with me spending my nights writing this. I'd also like to thank
the reviewers for doing an awesome job of finding all the places where
I could have done better. I hope I did justice to their efforts.
www.it-ebooks.info
About the Reviewers
Max Kirchoff built his first website in 1996 on a little hosting service called
GeoCities. He was not only immediately fascinated by the ability to distribute
information with a graphical interface, but was also frustrated with how difficult
it was to do interesting things with those early web browsers. As time passed and
the technology evolved, Max built more and more websites, eventually working
as a consultant for e-commerce early adopter businesses and then with advertising
agencies, building campaigns that were on the bleeding edge of the Web. Along
the way, he has worked on everything from leading the implementation of service-
oriented architecture to UX prototyping and a thousand things in between. JavaScript
was never his favorite language, but after working with a friend who "loved JS,"
he also came around and saw the strength and flexibility it provided for building
beautiful and powerful web applications.
Max currently works for Google, where he works closely with advertisment platform
partners to inform and enhance their web interfaces for better user experience.
www.it-ebooks.info
Michael Smith is a developer and consultant with 15 years of experience. He has
worked in a broad range of industries, including banking, finance, e-commerce,
and oil. He is passionate about delivering high-quality software that actually meets
and exceeds the client's needs. To this end, he is an advocate of putting the business
front and center when developing software and exploring ways to encourage better
communication between all stakeholders in a project.
www.it-ebooks.info
www.PacktPub.com
Did you know that Packt offers eBook versions of every book published, with PDF and ePub
files available? You can upgrade to the eBook version at www.PacktPub.com and as a print
book customer, you are entitled to a discount on the eBook copy. Get in touch with us at
[email protected] for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a
range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.
https://www2.packtpub.com/books/subscription/packtlib
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book
library. Here, you can search, access, and read Packt's entire library of books.
Why subscribe?
• Fully searchable across every book published by Packt
• Copy and paste, print, and bookmark content
• On demand and accessible via a web browser
www.it-ebooks.info
www.it-ebooks.info
Table of Contents
Preface vii
Chapter 1: A Typical JavaScript Project 1
The core idea of domain-driven design 2
Managing an orc dungeon 3
Inside the dungeon 4
Managing incoming prisoners 5
The current state of the art 6
Digital dungeon management 6
Specification 7
Tracking available cells 8
Starting outgoing transfers 9
Tracking the state of incoming transfers 9
Initiating incoming transfers 10
From greenfield to application 10
The first route and model 11
Creating the model 12
The first route and loading the dungeon 12
Displaying the page 13
Gluing the application together via express 14
Moving the application forward 15
Another look at the problem 16
Thinking in an MVC web application 16
Understanding the core problem 17
Communication is key 18
The concepts of domain-driven design 19
It is all about distractions 20
Focus on the problem at hand 21
Further reading 21
Summary 22
[i]
www.it-ebooks.info
Table of Contents
[ ii ]
www.it-ebooks.info
Table of Contents
[ iii ]
www.it-ebooks.info
Table of Contents
[ iv ]
www.it-ebooks.info
Table of Contents
[v]
www.it-ebooks.info
www.it-ebooks.info
Other documents randomly have
different content
PERSONAL POLITICS
The view which has been taken of the subject by Beccaria and
other modern writers appears to be erroneous or defective in some of
the most important circumstances relating to this question.
First objection. It is assumed as a general maxim, that, ‘it is not the
intensity of punishment, but its duration, which makes the greatest
impression on the human mind.’
This maxim will be found to be in direct opposition to all
experience, and to every principle of human nature. It supposes that
a number of impressions, feeble in themselves, and dissipated over a
long interval of time, produce a stronger effect upon the mind, than a
single object, however powerful and striking, presented to it at once:
that is, that the passions are excited more by reason than
imagination, by the real, than by the apparent quantity of good or
evil. This principle is indeed, in general, denied by Mr. Bentham, but
admitted by him, as far as relates to the influence of the fear of death
on malefactors. If it be true with respect to them in particular (which
there is reason to doubt,) it is not because the fear of a continued
punishment influences them more than the fear of an intense one,
but because death is to them not an intense punishment.
Again, it has been said, that ‘crimes are more effectually prevented
by the certainty than by the severity of the punishment.’ Now I
cannot think that this is either self-evident, or true universally and in
the abstract. It is not true of human nature in general, and it is still
less so as applied to the more lawless and abandoned classes of the
community. It is evident from the very character of such persons,
that if they are not to be acted upon by violent motives, by what
appeals strongly to their imagination and their passions, they cannot
be acted upon at all, they are out of the reach of all moral discipline.
The dull, sober certainties of common life, and the real consequences
of things when set in competition with any favourite inclination, or
vicious indulgence, they altogether despise. It is only when the
certainty of punishment is immediate, obvious, and connected with
circumstances, which strike upon the imagination, that it operates
effectually in the prevention of crimes. This principle is however
true, as it has been sometimes applied to cases where the law has
become a dead letter. When a moderate punishment is strictly and
vigorously enforced, and a severe punishment is as generally and
systematically evaded, the mind will, undoubtedly, be more affected
by what it considers as a serious reality, than by what it will regard
as an idle threat. So far the principle is true in its application, but no
farther.
First maxim. It is not the real, but the apparent severity of the
punishment which most effectually deters from the commission of
crimes. For this reason, an intense punishment will have more effect
than a continued one, because more easily apprehended. Neither is
the certainty of punishment to be depended on, except when it is
apparent. It is not the calculation of consequences, but their
involuntary and irresistible impression on the mind that produces
action. The laws to prevent crimes must appeal to the passions of
men, and not to their reason: for crimes proceed from passion, and
not from reason. If men were governed by reason, laws would be
unnecessary.
Second objection. It seems to be taken for granted by speculative
writers, (at least the contrary is not stated with sufficient
distinctness) that punishment operates by terror alone, or by the fear
which each individual has of the consequences to himself.
It is indeed a prevailing maxim of philosophy, that self-interest is
the sole spring of action, and it has thus probably been inferred, that
the fear of punishment could only operate on this principle of cool,
calculating self-interest. But it is quite certain that sympathy with
others, whatever may be its origin, is, practically speaking, an
independent and powerful principle of action. The opinions and
feelings of others do actually and constantly influence our conduct,
in opposition to our strongest interests and inclinations. That
punishment, therefore, will not be the most dreaded, nor,
consequently, the most effectual, which is the greatest to the
individual, unless it is at the same time thought so by others, and
expresses the greatest general disapprobation of the crime. Thus,
though a malefactor, consulting only his own inclinations or feelings,
might prefer death to perpetual imprisonment and hard labour, yet
he may regard it as the worst of punishments, in as far as it
demonstrates the greatest abhorrence and indignation in the
community against the crime.
Second maxim. Punishment operates by sympathy, as well as by
terror. Penal laws have a tendency to repress crimes not more by
exciting a dread of the consequences, than by marking the strong
sense entertained by others of their enormity, and the detestation in
which they are held by mankind in general. The most severe laws will
always be the most effectual, as long as they are expressions of the
public sentiment; but they will become ineffectual, in proportion as
the sentiment is wanting. The disproportion between the crime and
the punishment in the public opinion, will then counteract the dread
of the severity of the law. Setting this feeling aside, the most severe
laws will be the most effectual. The argument drawn from the
inefficacy of severe punishments, when inflicted on trifling or
common offences, does not prove that they must be ineffectual, when
applied to great crimes, which rouse the public indignation and
justify the severity.
Third objection. It is farther implied in the foregoing statements,
that the only object of punishment is to prevent actual crimes, or that
those laws are the best, which most effectually answer this end by
deterring criminals.
This I also conceive to be a narrow and imperfect view of the
question, which respects not merely the motives and conduct of
criminals, but the motives and sentiments of the community at large.
It is of the first importance that the ill disposed should be coerced,
but it is also of importance that they should be coerced in such a
manner, and by such means, as it is most consistent with the public
morals to employ. In defending the state, we are not to forget that
the state ought to be worth defending. As the sentiments of society
have a powerful effect in enforcing the laws, so the laws re-act
powerfully on the sentiments of society. This is evident with respect
to barbarous punishments. The evil of a law operating in this way on
manners, by holding out an example of cruelty and injustice,
however effectual it might be found, is not denied. In like manner, a
law falling short of or disappointing the just indignation and moral
sense of the community, is, for the same reason, faulty as one that
exceeds and outrages it. One end of punishment, therefore, is to
satisfy this natural sense of justice in the public mind, and to
strengthen the opinion of the community by its act. As the arm of
justice ought not to be mocked and baffled by the impunity of
offences, so neither ought it to be unnerved by thwarting and
prevaricating with the common sentiments of mankind, or by
substituting remote, indirect, and artificial punishments for obvious
and direct ones. I call a punishment natural when it is dictated by the
passion excited against the crime. A punishment will therefore be the
most beneficial when it arises out of, and co-operates with that
strong sense of right or wrong, that firm and healthy tone of public
sentiment, which is the best preservative against crime.
Illustration. Thus even if it were shewn that perpetual
imprisonment and hard labour would be equally effectual in
deterring malefactors from the commission of murder, it would by
no means necessarily follow, that this mode of punishment would be
preferable to capital punishment, unless it could at the same time be
made to appear that it would equally enforce the principle of the
connexion between the crime and the punishment, or the rule of
natural justice, by which he who shews himself indifferent to the life
of another, forfeits his own. There is a natural and home-felt
connexion between the hardened obduracy which has shewn itself
insensible to the cries of another for mercy and the immediate burst
of indignation which dooms the criminal to feel that he has no claims
on the pity of others: but there is no connexion, because there is no
ascertainable proportion, in the mind either of the criminal or the
public, between the original crime, and the additional half-hour in
the day after the lapse of twenty years, which the malefactor is
condemned to labour, or the lash of the whip which urges him to
complete his heavy task. That reasoning which stops the torrent of
public indignation, and diverts it from its object only to dole it out to
its miserable victim, drop by drop, and day by day, through a long
protracted series of time with systematic, deliberate, unrelenting
severity, is in fact neither wise nor humane. Punishments of this kind
may be so contrived as to intimidate the worst part of mankind, but
they will also be the aversion of the best, and will confound and warp
the plain distinctions between right and wrong.
Third maxim. The end of punishment is not only to prevent actual
crimes, but to form a standard of public opinion, and to confirm and
sanction the moral sentiments of the community. The mode and
degree of the punishment ought, therefore, to be determined with a
view to this object, as well as with a view to the regulation of the
police.
Fourth objection. The theory here alluded to, is farther
objectionable in this, that it makes familiarity with the punishment
essential to its efficacy, and therefore recommends those
punishments, the example of which is the most lasting, and, as it
were, constantly before the eyes of the public, as the most salutary.
On the contrary, those punishments are the best which require the
least previous familiarity with objects of guilt and misery to make
them formidable, which come least into contact with the mind, which
tell at a distance, the bare mention of which startles the ear, which
operate by an imaginary instead of an habitual dread, and which
produce their effect once for all, without destroying the erectness and
elasticity of social feeling by the constant spectacle of the
degradation of the species. No one would wish to have a gibbet
placed before his door, to deter his neighbours from robbing him.
Punishments which require repeated ocular inspection of the evils
which they occasion, cannot answer their end in deterring
individuals, without having first operated as a penance on society.
They are a public benefit only so far as they are a public nuisance.
Laws framed entirely on this principle, would convert the world into
a large prison, and divide mankind into two classes, felons and their
keepers!
Maxim fourth. Those punishments are the best which produce the
strongest apprehension, with the least actual suffering or
contemplation of evil. Such is in general the effect of those
punishments which appeal to the imagination, rather than to our
physical experience; which are immediately connected with a
principle of honour, with the passions in general, with natural
antipathies, the fear of pain, the fear of death, etc. These
punishments are, in Mr. Bentham’s phrase, the most economical;
they do their work with the least expense of individual suffering, or
abuse of public sympathy. Private punishments are, so far, preferable
to public ones.
General inference. There ought to be a gradation of punishments
proportioned to the offence, and adapted to the state of society.
In order to strike the imagination and excite terror, severe
punishments ought not to be common.[66]
To be effectual, from the sympathy of mankind in the justice of the
sentence, the highest punishments ought not to be assigned to the
lowest or to very different degrees of guilt. The absence of the
sanction of public opinion not only deadens the execution of the law,
but by giving confidence to the offender, produces that sort of
resistance to it, which is always made to oppression. The ignominy
attached to the sentence of the law, is thus converted into pity. If the
law is enacted but not enforced, this must either be to such a degree
as to take away the terror of the law, or if the terror still remains, it
will be a terror of injustice, which will necessarily impair the sense of
right and wrong in the community. But if the law is regularly carried
into execution, the effect will be still worse. In general, all laws are
bad which are not seconded by the manners of the people, and laws
are not in conformity with the manners of the people when they are
not executed. This is the case at present with a great proportion of
the English laws. Is it to be wondered at that they should be so?
Manners have changed, and will always change insensibly, and
irresistibly, from the force of circumstances. The laws, as things of
positive institution, remain the same. So that without a constant,
gradual assimilation of the laws to the manners, the manners will, in
time, necessarily become at variance with the laws, and will render
them odious, ineffectual, and mischievous—a clog, instead of a
furtherance to the wheels of justice.
NOTES
FUGITIVE WRITINGS
THE FIGHT
First republished in Literary Remains, vol. II. p. 193. For another
account of the fight and, more particularly, of the journey home, see
P. G. Patmore’s My Friends and Acquaintance, III. 41, et seq. The
fight (between Hickman, the ‘Gas-man’ and Bill Neat) took place on
Dec. 11, 1821. For an account of Tom Hickman (who was thrown
from a chaise and killed in the following December) see Pierce Egan’s
Boxiana, where particulars will be found of all the ‘Fancy’ heroes
referred to by Hazlitt in this essay.
PAG
E ‘The fight,’ etc. Cf. Hamlet, Act II. Sc. 2.
1. Jack Randall’s. Cf. vol. VI. (Table-Talk), note to p. 202.