Design And Model View Controller - NCSU

2y ago
37 Views
2 Downloads
1.10 MB
19 Pages
Last View : 12d ago
Last Download : 3m ago
Upload by : Annika Witter
Transcription

1/26/2016Design and Model‐View‐ControllerCSC216CSC216: Programming Concepts Sarah Heckman1Design Goal: decide the structure of the software and thehardware configurations that support it. How individual classes and software components worktogether in the software system– Small programs: 10 classes and interfaces– Medium programs: 1000s of classes and interfaces Design for single user applications different from webapplications and mobile applications Software Artifacts: design documents, class diagrams,other UML diagramsCSC216: Programming Concepts Sarah Heckman21

1/26/2016OO Design Discover classes (and their state)– What are the useful entities or concepts in yourproject requirements? Determine the responsibilities of each class– What should your class do? How does you classmanipulate its data? Describe the relationships between the classes– Do classes have instances of other classes? Does amethod of a class need to use an instance of anotherclass?CSC216: Programming Concepts Sarah Heckman3Finding Candidate Classes and Methods Candidate Classes (and state)– Nouns– You will determine if the noun is an appropriateobject or appropriate state Candidate Methods– Verbs– You will determine what class the method is mostappropriate for. Use CRC cards to help identify candidate classesCSC216: Programming Concepts Sarah Heckman42

1/26/2016University Registration System University XYZ has three types of students:undergraduates, masters, and PhDs. Allstudents can register for courses using theRegistration System.CSC216: Programming Concepts Sarah Heckman5UML UML: Unified Modeling Language– Models object‐oriented software– Convergence from three earlier modeling languages OMT (James Rumbaugh) OOSE (Ivar Jacobson) Booch (Grady Booch) Overseen by the Object Mentor Group (OMG):(www.omg.org)CSC216: Programming Concepts Sarah Heckman63

1/26/2016Types of UML Diagrams Use Case DiagramsClass DiagramsSequence DiagramState Chart DiagramCSC216: Programming Concepts Sarah Heckman7Use Case Diagrams How the system provides service(s) to the actorsthat will use itEnter PlayerInfoVisit JailGo to JailPass GoCellGo to �MovePlayer«include»Roll DicePurchaseTradable Cell«extend»«avoid»«extend»«include»Get OutBuy HouseSwitch TurnPay Rent«include»Draw CardCSC216: ProgrammingofConcepts Sarah HeckmanJailPlay More ThanOne Turn in ude»«extend»View InformationBad Player«include»84

1/26/2016Class Diagrams Classes and relationships between themCSC216: Programming Concepts Sarah Heckman9Sequence Diagram Sequence of actions (method calls) to complete a scenarioCSC216: Programming Concepts Sarah Heckman105

1/26/2016State Chart Diagrams How an object changes state when performing a taskCSC216: Programming Concepts Sarah Heckman11Creating UML Diagrams Commercial or open‐source tools––––Microsoft VisioCommercial Eclipse Plug‐insViolet UML (open source)Dia (freeware)CSC216: Programming Concepts Sarah Heckman126

1/26/2016Class Diagrams in DepthCSC216: Programming Concepts Sarah Heckman13ClassesNameStateBehaviorsCSC216: Programming Concepts Sarah Heckman147

1/26/2016ClassesNameStateBehaviorsCSC216: Programming Concepts Sarah Heckman15Generalization (is‐a) Generalization relationships show inheritance The child classes inherit the state and behaviorof the parent class– An UndergraduateStudent is‐a Student!Parent ClassChild ClassCSC216: Programming Concepts Sarah Heckman168

1/26/2016Composition (has‐a) Composition is when one class has an instance of another class– Fields– Parameters Many ways to model in UML depending on type of compositionrelationship In assignments, requiring a composition relationship meansthere MUST be a has‐a relationship in the diagram– It doesn’t have to use the composition UML connector of a solid diamond– It may be modeled using association (arrow) or aggregation (opendiamond) connectorsCSC216: Programming Concepts Sarah Heckman17 Indicated by a solid arrow line fromthe source class to the target class Can be bi-directional representedby lines without arrow headsAssociationConnectorshas-aDon’t usually put theassociation down as anattribute in the classCSC326: Software Engineering NC State Software Engineering FacultyL13 ‐ 189

1/26/2016Properties: Attributes vs. Associations If attributes and associations are essentially the samething, when should I use each one? Attributes– Small things (Strings, primitives, Dates, etc.)– Part of existing library– Immutable value objects Associations– Significant classes– Part of what will be implemented– Mutable referencesCSC326: Software Engineering NC State Software Engineering FacultyL13 ‐ 19Aggregation vs. Composition ConnectorsWhole‐Part Relationship Aggregation: stronger association (unidirectional)– Ex. A dept contains a set of employees– Ex. A faculty contains a set of teachers– A white diamond at the end of the association next to theaggregate class– The part can exist separate from the whole Composition: stronger aggregation (unidirectional)– Ex. Invoice– InvoiceLine– A black diamond on the end of association next to thecomposite class– The part cannot exist separate from the wholeCSC326: Software Engineering NC State Software Engineering FacultyL13 ‐ 2010

1/26/2016Composition : Programming Concepts Sarah onAssociationAbstract MethodAbstractClassInheritanceDependencyCSC216: Programming Concepts Sarah Heckman2211

1/26/2016Evaluating a Class/Class Diagram1. Intention‐revealing naming: Does the name of the objectconvey its abstractions? Does the abstraction have a naturalmeaning and use in the domain?2. Single Responsibility: Do the name, main responsibilitystatement data and functions align?CSC326: Software Engineering NC State Software Engineering FacultyL13 ‐ 23Sequence Diagrams How objects collaborate within a specifiedscenario– Behavior of the objects– Sequence of method calls An object’s lifetime is represented vertically– A rectangle (activation bar) represents when theobject is active Method is on the stackCSC216: Programming Concepts Sarah Heckman2412

1/26/2016Sequence Diagrams (2) Messages are passed between objects using asolid arrow– Messages may be passed within an object (self‐call) Return messages point back to the calling objectand are shown in dashed arrows Drawing sequence diagrams help developersunderstand how to implement a scenario.CSC216: Programming Concepts Sarah Heckman25Sequence DiagramCSC216: Programming Concepts Sarah Heckman2613

1/26/2016Design Patterns “Each pattern describes a problem which occursover and over again in our environment, andthen describes the core of the solution to thatproblem, in such a way that you can use thissolution a million times over, without ever doingit the same way twice.”– Christopher AlexanderCSC216: Programming Concepts Sarah Heckman27Design Patterns (2) Descriptions of communicating objects andclasses– Participating classes– Roles and collaborations– Distribution of responsibilities Customized to solve a general design problem ina specific contextCSC216: Programming Concepts Sarah Heckman2814

1/26/2016Why Design Patterns? Don’t need to start from scratch to solve aprogramming problem– Reuse previous useful ideas Design patterns are the closest thing we have toa Design Handbook for software engineering Design patterns are not a silver bullet!!!Sometimes the best designs do NOT requiredesign patterns!!!CSC216: Programming Concepts Sarah Heckman29The Gang of Four THE book on Design Patterns23 design patternsMore in literatureBook focuses on C , but wehave an online reference forJava Patterns are found, notcreated!CSC216: Programming Concepts Sarah Heckman3015

1/26/2016Pattern Families Creational: process of object creation– Singleton Structural: composition of classes or objects Behavioral: ways in which classes or objectsinteract and distribute responsibility– State/Strategy– CommandCSC216: Programming Concepts Sarah Heckman31Model‐View‐Controller (MVC) Isolates business or domain logic from the input andpresentation Model: data underlying the application– Changes in state require notifying the view– Model abstracts the data storage (DB, POJOs, etc.) View: UI– A model may have many views Controller: receives input and initiates response by calling modelCSC216: Programming Concepts Sarah Heckman3216

1/26/2016MVC in Web Apps View: HTML or XHTML Controller: GET or POST input– Gives the GET or POST information to the objects Model: underlying domain logicCSC216: Programming Concepts Sarah Heckman33MVC in Java View / Controller: very tightly coupled– GUI Applications View (how the object is presented) and controller (howevents on the object are processed) belong to one UIobject Use generic components (i.e. JButton), which delegate tothe underlying “look and feel” (i.e. the operating system)– Console Applications View (console prompts) and controller (how user input isprocessed) typically belong to one (or more) UI objects. Model: underlying domain logicCSC216: Programming Concepts Sarah Heckman3417

1/26/2016Design Best Practices Classes should have cohesion– The extent to which the code for a class represents a singleabstraction– Degree to which the members of a class are related to thegeneral purpose of the class– Allows for reusability of the class in other programs Examples:– Student: only contains information relevant to a student– Courses: only contains information relevant to coursesCSC216: Programming Concepts Sarah Heckman35Design Best Practices (2) A program should have low coupling– A connection between two classes is a dependency orcoupling Instance of an object in the class Call another class to complete a task– Internal coupling: modifying another class’ data – avoid ifpossible!– Parameter coupling: using services provided by another class– unavoidable Highly coupled programs are difficult to write andmaintainCSC216: Programming Concepts Sarah Heckman3618

1/26/2016Design Best Practices (3) Data and behavior should be encapsulatedwithin a class or a package– Use packages to group together commonfunctionality Example: In an Android application, all Activities are partof the activity package– Information hiding: make data members private– Details about implementation are hidden withinclass and only exposed with public membersCSC216: Programming Concepts Sarah Heckman37References Laurie Williams, UML Class Diagram assDiagrams.pdf /content/RationalEdge/sep04/bell/ M. Fowler, UML Distilled, Third Edition, Addison‐Wesley, Boston, 2004.CSC216: Programming Concepts Sarah Heckman3819

Draw Card Get Out of Jail Pass Go Cell «extend» «extend» «extend» View Information «include» «include» «include» «include» Go to Jail «extend» Visit Jail Go to Free Parking «extend» Roll Dice Switch Turn «include» «include» Bad Player Play More Than One Tur

Related Documents:

grid orthographic drawing 3rd angle top view left view front view left view front view top view top view top view front view right view front view right view top view front view right view front view right view a compilation of drawings for developing the skill to draw in orthographic

Fig.4.1 Step response using P controller Fig.4.2 Fig.4.3 Fig.4.4 Fig.4.5 Step response using PID controller Fig.4.6 Comparison of bode plot for smith predictor and PI . Step response of IMC PDF control structure Step response of PDF controller Step response using PI controller Step response using PID controller Step response using PI controller

the so-called IBP inter-view prediction order, where left-side view (I view) is coded independently of other views, the right-side view (P view) may utilize inter-view predic-tion from the I view, and center view (B view) may be pre-dicted from both the I and P views. As can be seen the view order index values of the respective views (left, center,

fundamental concept in iOS programming We looked at basic concepts concerning view controllers last time Now, we'll look at some of the more advanced view controllers that iOS provides Tab Bar View Controller ,Table View Controller and Navigation View Controller 19 Wednesday, March 23, 2011

The Sun News View Release San Jose Mercury News View Release The Miami Herald View Release. Star Tribune View Release CEO World News View Release AZ Central . Poteau Daily News View Release The Evening Leader View Release Wapakoneta Daily News View Release Observer News Enterprise. View Release Valley City Times-Record

If you just purchased USB Controller board and the software, you may want to refer to the document - Connecting and Wiring AGNI USB Controller for the recommended wiring of the controller board in your system. Make sure and understand which controller you have to follow separate instructions for the 32-bit controller or older 16-bit controller.

Trimble Survey Controller Procedure Sheet Working with Total Stations and Trimble Survey Controller Create a job on the Controller: -Turn on your Controller and go into Survey Controller Software - -Create a new job by going into Files/New Job -Note to set the Scale Factor to 1.0 when working with a Total Station. Hit Accept to create your new job.

Controller Firmware Comment CMMS-ST-. From Version 1.3.0.1.14 Standard motor controller for stepper motors CMMS-AS-. From Version 1.3.0.1.16 Standard motor controller for servo motors CMMD-AS-. From Version 1.4.0.3.2 Standard double motor controller for servo motors Table 1.1 Controller and firmware versions For older versions: