CS16: UML’s Unified Modeling Language. UML Class Diagram A UML class diagram is a graphical tool that can aid in the design of a class. The diagram has.

Slides:



Advertisements
Similar presentations
Looking inside classes Fields, Constructors & Methods Week 3.
Advertisements

Based on Java Software Development, 5th Ed. By Lewis &Loftus
Chapter 13 – Introduction to Classes
Lesson 13 Introduction to Classes CS1 Lesson Introduction to Classes1.
The Line Class Suppose you are involved in the development of a large mathematical application, and this application needs an object to represent a Line.
CS0007: Introduction to Computer Programming Introduction to Classes and Objects.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 9 Classes.
Road Map Introduction to object oriented programming. Classes
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Java: Early Objects Third Edition by Tony Gaddis Chapter.
Evan Korth New York University Computer Science I Classes and Objects Professor: Evan Korth New York University.
Terms and Rules Professor Evan Korth New York University (All rights reserved)
1 Fall 2007ACS-1903 Chapter 6: Classes Classes and Objects Instance Fields and Methods Constructors Overloading of Methods and Constructors Scope of Instance.
Chapter 6: A First Look at Classes
UML Basics & Access Modifier
Copyright © 2012 Pearson Education, Inc. Chapter 13: Introduction to Classes.
A First Look At Classes Chapter 6. Procedural Programming In procedural- programming all the program functionality is written in a few modules of code.
Starting Out With Java 5 (Control Structures to Objects) Chapter 6 By Tony Gaddis Copyright © 2005 Pearson Addison-Wesley. All rights reserved.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Java: From Control Structures through Objects Third Edition.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Java: Early Objects Third Edition by Tony Gaddis Chapter.
Starting Out with Java: From Control Structures through Objects.
I NTRODUCTION TO PROGRAMMING Starting Out with Java: From Control Structures through Objects.
An Introduction to Java Chapter 11 Object-Oriented Application Development: Part I.
Copyright © 2012 Pearson Education, Inc. Chapter 13: Introduction to Classes.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Procedural and Object-Oriented Programming 13.1.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 13: Introduction to Classes.
An Object-Oriented Approach to Programming Logic and Design Chapter 3 Using Methods and Parameters.
Chapter 10 Classes and Objects In-Depth. Chapter 10 A class provides the foundation for creating specific objects, each of which shares the general attributes,
Chapter 3 (B) 3.5 – 3.7.  Variables declared in a function definition’s body are known as local variables and can be used only from the line of their.
AP Computer Science A – Healdsburg High School 1 Unit 9 - Why Use Classes - Anatomy of a Class.
Chapter 3 Introduction to Classes and Objects Definitions Examples.
CSci 162 Lecture 10 Martin van Bommel. Procedures vs Objects Procedural Programming –Centered on the procedures or actions that take place in a program.
Some odds and ends about Classes and Objects. 6-2 Object-Oriented Programming Object Data (Fields) Methods That Operate on the Data.
© 2010 Pearson Addison-Wesley. All rights reserved. 6-1 Chapter Topics Chapter 6 discusses the following main topics: –Classes and Objects –Instance Fields.
Lecture 19: Introduction to Classes Professor: Dr. Miguel Alonso Jr. Fall 2008 CGS2423/COP1220.
Copyright © 2012 Pearson Education, Inc. Chapter 13: Introduction to Classes.
Introduction to Classes, Objects, Methods and Attributes Lecture # 5.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 3 A First Look at Classes and Objects.
Topic 8Classes, Objects and Methods 1 Topic 8 l Class and Method Definitions l Information Hiding and Encapsulation l Objects and Reference Classes, Objects,
1 Static Variable and Method Lecture 9 by Dr. Norazah Yusof.
Starting Out With Java 5 Control Structures to Objects By Tony Gaddis Copyright © 2005, 2005 Pearson Addison-Wesley. All rights reserved. Chapter 6 Slide.
Topics Instance variables, set and get methods Encapsulation
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 13: Introduction to Classes.
Object Oriented Programming Lecture 3: Things OO.
CS 116 Object Oriented Programming II Acknowledgement: Contains materials provided by George Koutsogiannakis and Matt Bauer.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley The Unified Modeling Language
Introduction to Constructors Lecture # 4. Copyright © 2011 Pearson Education, Inc. 3-2 Arguments Passed By Value In Java, all arguments to a method are.
Computer Programming II Lecture 5. Introduction to Object Oriented Programming (OOP) - There are two common programming methods : procedural programming.
Chapter 6 A First Look at Classes. 2 Contents 1. Classes and objects 2. Instance Fields and Methods 3. Constructors 4. Overloading Methods and Constructors.
Copyright © 2011 Pearson Education, Inc. Starting Out with Java: Early Objects Fourth Edition by Tony Gaddis Chapter 3: A First Look at Classes and Objects.
Chapter 6 A First Look at Classes. 2 Contents 1. Classes and objects 2. Instance Fields and Methods 3. Constructors 4. Overloading Methods and Constructors.
Pointer to an Object Can define a pointer to an object:
Procedural and Object-Oriented Programming
Topics Procedural and Object-Oriented Programming Classes
Chapter 3 Classes & Objects
OBJECT ORIENTED PROGRAMMING II LECTURE 7 GEORGE KOUTSOGIANNAKIS
A first Look at Classes.
Review: Two Programming Paradigms
Chapter 3: Using Methods, Classes, and Objects
Introduction to Classes
Chapter 6: A First Look at Classes
Introduction to Classes
Chapter 3 Introduction to Classes, Objects Methods and Strings
OBJECT ORIENTED PROGRAMMING II LECTURE 8 GEORGE KOUTSOGIANNAKIS
Today’s topics UML Diagramming review of terms
Lecture 5- Classes, Objects and Methods
Introduction to Objects & Classes
Defining Classes and Methods
Lecture 8 Object Oriented Programming (OOP)
Presentation transcript:

CS16: UML’s Unified Modeling Language

UML Class Diagram A UML class diagram is a graphical tool that can aid in the design of a class. The diagram has three main sections. ClassName Attributes Methods UML diagrams are easily converted to Java class files. There will be more about UML diagrams a little later. The class name should concisely reflect what the class represents.

Attributes The data elements of a class defines the object to be instantiated from the class. The attributes must be specific to the class and define it completely. Example: A rectangle is defined by –length –width. The attributes are then accessed by methods within the class.

Data Hiding Another aspect of encapsulation is the concept of data hiding. Classes should not only be self-contained but they should be self-governing as well. Classes use the private access modifier on fields to hide them from other classes. Classes need methods to allow access and modification of the class’ data.

Methods The class’ methods define what actions an instance of the class can perform Methods headers have a format: AccessModifier ReturnType MethodName(Parameters) { //Method body. } Methods that need to be used by other classes should be made public.

Methods The attributes of a class might need to be: –changed, –accessed, and –calculated. The methods that change & access attributes are called Accessors and Mutators.

UML Data Type and Parameter Notation UML diagrams are language independent. UML diagrams use an independent notation to show return types, access modifiers, etc. Rectangle - width : double + setWidth(w : double) : void Access modifiers are denoted as: +public -private #protected

UML Data Type and Parameter Notation UML diagrams are language independent. UML diagrams use an independent notation to show return types, access modifiers, etc. Rectangle - width : double + setWidth(w : double) : void Variable types are placed after the variable name, separated by a colon.

Converting the UML Diagram to Code Putting all of this information together, a Java class file can be built easily using the UML diagram. The UML diagram parts match the Java class file structure. ClassName Attributes Methods class header { Attributes Methods }

Converting the UML Diagram to Code Rectangle - width : double - length : double + setWidth(w : double) : void + setLength(len : double): void + getWidth() : double + getLength() : double + getArea() : double The structure of the class can be compiled and tested without having bodies for the methods. Just be sure to put in dummy return values for methods that have a return type other than void.