Объектно-Ориентированное Программирование на C++, Лекция 4

Embed Size (px)

Citation preview

  • 1. UML -

2. ? ... , : ? ? ? 3. - , ? , . , .. 3 4. 4UML .UML ( ).UML ()Use CaseClass DiagramSequenceCollaborationStateActivityDeployment & Component 5. UML?UML asa sketch UML asa blueprint , UML asa programminglanguage , . 6. . UML. Use Case.uc Elements include extend precedes ""invokes: , . : .6 7. UseCase .: ( .): . ( .) 8. Use Case 2.0 , UML, RUP, - . 9. 9 Use Case SlicesSTART 1 2 3 4 5 6 7END1 USE CASE =USE CASE SLICESALT 1ALT 2ALT 3 . (DoD). . 10. 10 START 1 2 3 4 5 6 7END1. condition #1 -> result #1condition #2 -> result #2condition #3 -> result #3condition #n -> result #n2. START 1 2 3 4 5 6 7ENDcondition #1 -> result #13. START 1 2 3 4 5 6 7ENDcondition #1 -> result #1condition #2 -> result #2condition #3 -> result #3condition #n -> result #ncondition #n+1 -> result #n+1condition #n+2 -> result #n+2condition #n+3 -> result #n+3condition #n+4 -> result #n+4condition #n+5 -> result #n+5condition #N -> result #N 11. 11 01020304 Use Case 1Use Case 2Use Case 3Use Case 4SLICE 1.1 SLICE 1.1SLICE 1.2SLICE 2.1SLICE 1.1SLICE 1.2SLICE 2.1SLICE 3.1SLICE 4.1SLICE 1.1SLICE 1.2SLICE 2.1SLICE 3.1SLICE 4.1SLICE 2.2SLICE 3.2SLICE 4.2RELEASECANDIDATE 12. Use Case.Include , . , .12 13. Use Case.Extend , , . . , . ! Include Include, ( , include)13 14. Use Case.Generalization . UseCase ( ) .14 15. SparxEnterprise Architect ( ). : , , . 16. . UML. Class Diagram.class Elements- : + () : + 10..1 + 2*{} : , 16 17. 17 18. 18 19. . UML. Sequence.sd Elements - alt [ ][ ]: * . - 19 20. 20 21. 21 22. 22 23. 23 24. SOLID ?SRP . .OCP /. , .LSP . .ISP . , .DIP . . . . . 25. SRP: Single Responsibility Principle( ) class 01 SRP OFFCustomer+ GetName(): const char*OrderProduct+ CalculateTax(): double+ GetName(): const char*+ GetPrice(): double+ MakeReservation(): boolclass 01 SRP ONCustomer+ GetName(): const char*OrderProduct+ GetName(): const char*+ GetPrice(): doubleTaxCalculator+ CalculateTax(Product): doubleProductReserv ation+ ReserveProduct(Product): bool* 26. OCP: Open/Closed Principle (/) (, , ..) , .class 02 OCP OFFCustomer+ GetName(): const char*OrderProduct+ GetName(): const char*+ GetPrice(): doubleTaxCalculator+ CalculateTax(Product): doubleProductReserv ation+ ReserveProduct(Product): boolCatalogue+ FindByName(const char*): Productclass 02 OCP ONCustomer+ GetName(): const char*OrderProduct+ GetName(): const char*+ GetPrice(): doubleTaxCalculator+ CalculateTax(Product): doubleProductReserv ation+ ReserveProduct(Catalogue Product): bool+ FindByName(IFindSpecification): ProductinterfaceIFindSpecification+ isIt(Product): boolFindByNameSpecification+ isIt(Product): boolFindByGroupSpecification+ isIt(Product): bool* 27. LSP: LiskovSubstitution Principle ( ) CPP_Examples31_LSP, , , class Rectangle{protected:intwidth;intheight;public:Rectangle(intw, inth) : width(w), height(h) {};virtual void SetWidth(intvalue) { width = value; }virtual void SetHeight(intvalue) { height = value; }virtual intGetSquare() { return width * height; }};class Square : public Rectangle{public:Square(intw, inth) : Rectangle(w,w) {};virtual void SetWidth(intvalue) { width = value; height = value; }virtual void SetHeight(intvalue) { width = value; height = value; }}; 28. LSP: LSP (class diagram) class 03 LSPRectangle# height: int# width: int+ GetSquare(): int+ Rectangle(int, int) + SetHeight(int): void+ SetWidth(int): voidSquare+ SetHeight(int): void+ SetWidth(int): void+ Square(int, int) 29. ISP: Interface Segregation Principle ( ) CPP_Examples31_ISP , . : .class IBusinessMenu{protected:virtual constchar* GetFirstItem() =0 ;virtual constchar* GetSecondItem() =0;virtual constchar* GetCompot() =0 ;public:void PrintMenu(){if (GetFirstItem() != nullptr) std::cout