The presentation was created in the Apple Pages, and then converted to a MS PowerPoint format, due to that, on some slides may apper poor quality and ugly look.
2. Bibliography
• Martin Fowler,Patterns of Enterprise Appication Architecture
• Matt Zandstra , PHP5 Objects, Patters, and Practice
• http://www.ustream.tv - New York PHP channel
• Symfony Live Berlin 2012 - https://joind.in/event/view/1114
• http://scholar.google.pl
• http://pzielinski.com
2
10. Transaction Script
Advantages: Disadvantages:
• simple procedural model • difficult to maintenance
• works well with a simple • code duplication
data access layer
• easy implementation of use
cases
10
13. Table Module vs
Transaction Script
Advantages: Disadvantages:
• less duplication • weak support for
polymorphism
• encapsulation
• no support ORM
• more organized and
structured code
• easy implementation by
technology support
13
14. Domain Model #1
1. class Hotel
2. {
3. protected $_hotelId;
4. protected $_rooms;
5.
6. public function bookRoom(User $user, $fromDate, $toDate)
7. {
8. $room = $this->_getRoomBetweenDates($fromDate, $toDate);
9.
10. if (is_null($room)) {
11. return false;
12. }
13.
14. $booking = $room->bookRoom(User $user, $fromDate, $toDate);
15.
16. return $booking;
17. }
18. }
19.
20. class Room
21. {
22. protected $_roomId;
23. protected $_bookings = array();
24.
25. public function bookRoom(User $user, $fromDate, $toDate)
26. {
27. $days = $this->_getAmountOfDays($fromDate, $toDate);
28.
29. if ($days < = 7) {
30. $booking = new Booking($user, new ShortBookingStrategy($user, $days));
31. } else {
32. $booking = new Booking($user, new NormalBookingStrategy($user, $days));
33. }
34.
35. return $booking;
36. }
37. }
14
15. Domain Model #2
1. class NormalBookingPriceStrategy extends BookingPriceStrategy
2. {
3. public function getPrice()
4. {
5. $price = $this->_days * 80;
6.
7. if ($this->_user->isLoyal()) {
8. $price = $price / 2;
9. }
10.
11. return $price;
12. }
13.}
14.
15.class ShortBookingPriceStrategy extends BookingPriceStrategy
16.{
17. public function getPrice()
18. {
19. return $this->_days * 100;
20. }
21.}
15
16. Domain Model vs
Procedural Pattern
• time-consuming
implementation
Advantages: • additional patterns
Disadvantages:
• prevents logic duplication - ORM
• more code readability - data source
• independence from the data
source
• much easier to unit test
16
17. SUMMARY
programming
scalability
language
modularity time-consuming
testable
size of project
(integration test)
skill of the developers
17
34. Advantages of Design
Pattern?
• speed up the development process,
• helps to prevent issues that can cause
major problems,
• patterns allow developers to communicate
using well-known, well understood names
for software interactions
34