Brief, short introduction to software design patters and good practises.
Apologises for any bad formatting but the presentation was made in Keynote and exported to .ppt format for slideshare.
7. 7
Implementation related
to the context
programmingprogramming
languagelanguage
scalabilityscalability
modularitymodularity
testabletestable
(integration test)(integration test)
time-consumingtime-consuming size of projectsize of project
8. 8
ContextContext ISIS
related to therelated to the
programmingprogramming
languagelanguage
Design patternsDesign patterns
IS NOTIS NOT relatedrelated
to theto the
programmingprogramming
languagelanguage
10. 10
Transaction Script
• simple procedural model
• works well with a simple
data access layer
• easy implementation of use
cases
• difficult to maintenance
• code duplication
Disadvantages:Advantages:
13. 13
Table Module vs
Transaction Script
• less duplication
• encapsulation
• more organized and
structured code
• easy implementation by
technology support
• weak support for
polymorphism
• no support ORM
Disadvantages:Advantages:
14. 14
Domain Model #11. 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. }
15. 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.}
16. 16
Domain Model vs
Procedural Pattern
• prevents logic duplication
• more code readability
• independence from the data
source
• much easier to unit test
• time-consuming
implementation
• additional patterns
- ORM
- data source
Disadvantages:Advantages:
34. 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