You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: public/docs/ts/latest/guide/component-communication.jade
+44-1Lines changed: 44 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -544,8 +544,51 @@ figure.image-display
544
544
545
545
## #8: A malicious hero steals the job — issues with multiple facades
546
546
547
-
_Content_
547
+
With moving the business logic to `JobService`, we made a great design decision, as we can manage business and UI logic separately. However the _way we use_
548
+
`JobService` has a flaw. Right now both `HeroJobBoard` and `InvitedHero` use a single facade to access `JobService` functionality, and through this facade
549
+
these components can access all operations, and not only the ones intended for their use. The following blueprint shows how the members of `JobService` are used:
This design allows that components can invoke operations that were not available for them with properly designed facades. We'll it by adding a new `stealJob()` method
567
+
to `InvitedHero` so that a hero can maliciously steal a job assigned to another hero:
Now, an `InvitedHero` instance can behave as if it were `HeroJobBoard` and invoke the `assign()` method of `JobService`, passing itself as the winner hero.
578
+
579
+
When we run the application, after the job is assigned to a hero, all other heroes (even those who have not undertaken the job before) can click the **I steal the job!**
580
+
button and scrounge the job. This screenshot shows that Magneta has been assigned the job:
581
+
582
+
figure.image-display
583
+
img(src="/resources/images/devguide/component-communication/winner-announced-ui.png"alt="The winner is announced")
584
+
585
+
:marked
586
+
Now, Bombasto can use the **I steal the job button!**, and the job goes to him. (It's not a great consolation for Magneta that she can steal the job back...)
587
+
588
+
figure.image-display
589
+
img(src="/resources/images/devguide/component-communication/job-stolen-ui.png"alt="The job is stolen")
590
+
591
+
:marked
549
592
## #9: Preventing stealth — using multiple facades
0 commit comments