Design and MVC

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/19

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

20 Terms

1
New cards

Design

• Goal: decide the structure of the software and the hardware configurations that support it.

• How individual classes and software components work together in the software system

– Small programs: ~ 10 classes and interfaces

– Medium programs: 1000s of classes and interfaces

• Design for single user applications different from web applications and mobile applications

• Software Artifacts: design documents, class diagrams, other UML diagrams

2
New cards

OO Design

• Discover classes (and their state)

– What are the useful entities or concepts in your project requirements?

• Determine the responsibilities of each class

– What should your class do?

How does you class manipulate its data?

• Describe the relationships between the classes

– Do classes have instances of other classes?

Does a method of a class need to use an instance of another class?

3
New cards

Finding Classes and Methods

• Candidate Classes (and state)

– Nouns

– You will determine if the noun is an appropriate object or appropriate state

• Candidate Methods

– Verbs

– You will determine what class the method is most appropriate for.

• Use CRC cards to help identify candidate classes

<p>• Candidate Classes (and state) </p><p>– Nouns </p><p>– You will determine if the noun is an appropriate object or appropriate state </p><p>• Candidate Methods </p><p>– Verbs </p><p>– You will determine what class the method is most appropriate for. </p><p>• Use CRC cards to help identify candidate classes </p>
4
New cards
<p>Exercise 2</p>

Exercise 2

knowt flashcard image
5
New cards

Unified Modeling Language

• 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)

Creating: • Commercial or open-source tools – Microsoft Visio – Commercial Eclipse Plug-ins – Dia (freeware) – UMLetino (web) or UMLet (Eclipse plugin) – PlantUML (“program” diagrams) – Draw.io (web) – LucidChart (free for students)

6
New cards

Full Class Diagram (UML is a type of)

knowt flashcard image
7
New cards

Class in UML

• Class Names

– In italics for abstract classes

– In <> brackets for interfaces (or with a purple I icon)

• State & Behaviors

– Access modifier

• Private: “-” or red square

• Public: “+” or green circle

• Protected: “#” or yellow triangle

• Default: no symbol

– Field/method name

– Behaviors/constructor only: parameter list

– Return type visibility name[(parameters:type,…)]:type

Constants have final values shown. B/c they are static, an underline is used.

Static fields/methods are also shown with an underline

<p>• Class Names </p><p>– In italics for abstract classes </p><p>– In &lt;&gt; brackets for interfaces (or with a purple I icon)</p><p>• State &amp; Behaviors </p><p>– Access modifier </p><p>• Private: “-” or red square </p><p>• Public: “+” or green circle </p><p>• Protected: “#” or yellow triangle </p><p>• Default: no symbol </p><p>– Field/method name </p><p>– Behaviors/constructor only: parameter list </p><p>– Return type visibility name[(parameters:type,…)]:type</p><p>Constants have final values shown. B/c they are static, an underline is used.</p><p>Static fields/methods are also shown with an underline</p>
8
New cards

Generalization(is-a) Relationship

• Generalization relationships show inheritance

• The child classes inherit the state and behavior of the parent class

– A Course is-a Event!

• A dashed line shows a class implementing and interface

<p>• Generalization relationships show inheritance </p><p>• The child classes inherit the state and behavior of the parent class </p><p>– A Course is-a Event!</p><p> • A dashed line shows a class implementing and interface</p><p></p>
9
New cards

Composition

• Composition is when one class has an instance of another class

– Fields

– Parameters

• Many ways to model in UML depending on type of composition relationship

• In assignments, requiring a composition relationship means there 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 (open diamond) connectors

<p>• Composition is when one class has an instance of another class </p><p>– Fields </p><p>– Parameters </p><p>• Many ways to model in UML depending on type of composition relationship </p><p>• In assignments, requiring a composition relationship means there MUST be a has-a relationship in the diagram </p><p>– It doesn’t have to use the composition UML connector of a solid diamond </p><p>– It may be modeled using association (arrow) or aggregation (open diamond) connectors</p>
10
New cards

Association Container

knowt flashcard image
11
New cards

Attribute vs Association

• If attributes and associations are essentially the same thing, 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 references

<p>• If attributes and associations are essentially the same thing, when should I use each one?</p><p> • Attributes </p><p>– Small things (Strings, primitives, Dates, etc.) </p><p>– Part of existing library </p><p>– Immutable value objects </p><p>• Associations </p><p>– Significant classes </p><p>– Part of what will be implemented </p><p>– Mutable references</p>
12
New cards

Aggregation Connector

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 the aggregate class

– The part can exist separate from the whole

<p>stronger association (unidirectional) </p><p>– Ex. A dept contains a set of employees </p><p>– Ex. A faculty contains a set of teachers</p><p> – A white diamond at the end of the association next to the aggregate class </p><p>– The part can exist separate from the whole</p>
13
New cards

Composition Connector

stronger aggregation (unidirectional)

– Ex. Invoice– InvoiceLine

– A black diamond on the end of association next to the composite class

– The part cannot exist separate from the whole (the whole controls the lifecycle of the part).

14
New cards
<p>Whole Class Diagram</p>

Whole Class Diagram

knowt flashcard image
15
New cards
<p>Exercise 2</p>

Exercise 2

What is the class header of Y?

public class Y implements Z

What is the class header of W?

public class W extends X

What is a minimal implementation of the constructor for class X to avoid NullPointerExceptions? (Note that the parameter for X’s constructor should be named x.)

public X(int x) {

   this.x = new x;

   this.y = new Y();

}

What would be an appropriate type for list given its multiplicity?

ArrayList or List or LinkedList

What is a minimal implementation of the constructor for class W to avoid a NullPointerException?

public W() {

   super(DEFAULT_VALUE);

}

Provide the code for Interface Z.

public interface Z {

      void z();

}

<p><span>What is the class header of Y?</span></p><p><span>public class Y implements Z</span></p><p><span>What is the class header of W?</span></p><p><span>public class W extends X</span></p><p><span>What is a minimal implementation of the constructor for class X to avoid NullPointerExceptions? (Note that the parameter for X’s constructor should be named x.)</span></p><p><span>public X(int x) {</span></p><p><span>&nbsp;&nbsp;&nbsp;this.x = new x;</span></p><p><span>&nbsp;&nbsp;&nbsp;this.y = new Y();</span></p><p><span>}</span></p><p><span>What would be an appropriate type for list given its multiplicity?</span></p><p><span>ArrayList or List or LinkedList</span></p><p><span>What is a minimal implementation of the constructor for class W to avoid a NullPointerException?</span></p><p><span>public W() {</span></p><p><span>&nbsp;&nbsp;&nbsp;super(DEFAULT_VALUE);</span></p><p><span>}</span></p><p><span>Provide the code for Interface Z.</span></p><p><span>public interface Z {</span></p><p><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;void z();</span></p><p><span>}</span></p>
16
New cards

Evaluating a Class/Class Diagram

<p></p>
17
New cards

Design Pattern

• Descriptions of communicating objects and classes

– Participating classes

– Roles and collaborations

– Distribution of responsibilities

• Customized to solve a general design problem in a specific context

• Don’t need to start from scratch to solve a programming problem

– Reuse previous useful ideas

• Design patterns are the closest thing we have to a Design Handbook for software engineering

• Design patterns are not a silver bullet!!!

Sometimes the best designs do NOT require design patterns!!!

• Patterns are found, not created!

18
New cards

Pattern Families

• Creational: process of object creation

– Singleton

• Structural: composition of classes or objects

• Behavioral: ways in which classes or objects interact and distribute responsibility

– State/Strategy

– Command

19
New cards
<p>Model View Controller(MVC)</p>

Model View Controller(MVC)

• Isolates business or domain logic from the input and presentation

• 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 model

<p>• Isolates business or domain logic from the input and presentation </p><p>• Model: data underlying the application </p><p>– Changes in state require notifying the view </p><p>– Model abstracts the data storage (DB, POJOs, etc.)</p><p> • View: UI </p><p>– A model may have many views </p><p>• Controller: receives input and initiates response by calling model</p><p></p>
20
New cards

Design Best Practices

• Classes should have cohesion

– The extent to which the code for a class represents a single abstraction

– Degree to which the members of a class are related to the general 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 courses

• A program should have low coupling

– A connection between two classes is a dependency or coupling

• Instance of an object in the class

• Call another class to complete a task

– Internal coupling: modifying another class’ data – avoid if possible!

– Parameter coupling: using services provided by another class – unavoidable

• Highly coupled programs are difficult to write and maintain

Data and behavior should be encapsulated within a class or a package

– Use packages to group together common functionality

• Example: In an Android application, all Activities are part of the activity package

– Information hiding: make data members private

– Details about implementation are hidden within class and only exposed with public members