Mapping associations with and without attributes using: references (reference collections) association arrays.

Slides:



Advertisements
Similar presentations
Transparency No. 1 Java Collection API : Built-in Data Structures for Java.
Advertisements

Copyright © 2015 Pearson Education, Inc. Database Design Chapters 17 and
1 CS 426 Senior Projects Chapter 9: Relationships Chapter 10: Inheritance and Polymorphism [Arlow and Neustadt, 2005] February 12, 2009.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 7 Data Modeling Using the Entity- Relationship (ER) Model.
Modeling Data The Entity Relationship Model (ER) For Database Design.
Chapter 4 Entity-Relationship modeling Transparencies © Pearson Education Limited 1995, 2005.
Relational Databases What is a relational database? What would we use one for? What do they look like? How can we describe them? How can you create one?
Databases Illuminated Chapter 7 The Object-Oriented Model.
APPENDIX C DESIGNING DATABASES
A Bridge to Your First Computer Science Course Prof. H.E. Dunsmore Interfaces.
Chapter 9 - Implementing Association Relationships1 Chapter 9 Implementing Association Relationships.
CS 405G Introduction to Database Systems
Data Modeling Using the Entity-Relationship Model
DeSiamorewww.desiamore.com/ifm1 Database Management Systems (DBMS)  B. Computer Science and BSc IT Year 1.
CSE314 Database Systems Data Modeling Using the Entity- Relationship (ER) Model Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson Ed Slide Set.
Chapter 3 Data Modeling Using the Entity-Relationship (ER) Model.
the Entity-Relationship Model
Classes and objects Practice 2. Basic terms  Classifier is an element of the model, which specifies some general features for a set of objects. Features.
Dr. Mohamed Osman Hegaz1 Conceptual data base design: The conceptual models: The Entity Relationship Model.
UML and its Use-Case Modeling Professor Chen School of Business Gonzaga University Spokane, WA 99258
Database. Basic Definitions Database: A collection of related data. Database Management System (DBMS): A software package/ system to facilitate the creation.
CSCI-383 Object-Oriented Programming & Design Lecture 9.
Chapter 5 Entity–Relationship Modeling
Principles of Database Systems With Internet and Java Applications Today’s Topic Chapter 2: Representing Information with Data Models The lecture notes.
1 ER Modeling BUAD/American University Entity Relationship (ER) Modeling.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 7 Data Modeling Using the Entity- Relationship (ER) Model.
A Singleton Puzzle: What is Printed? 1 public class Elvis { public static final Elvis INSTANCE = new Elvis(); private final int beltSize; private static.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
UML Diagrams: Class Diagrams The Static Analysis Model Instructor: Dr. Hany H. Ammar Dept. of Computer Science and Electrical Engineering, WVU.
Composition - 1 J. Sant.. Agenda Define Composition Reuse and Composition. Composition in Java. Composition Exercise with simple containment.
Chapter 3 Data Modeling Using the Entity- Relationship (ER) Model Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2008.
Interfaces. –An interface describes a set of methods: no constructors no instance variables –The interface must be implemented by some class. 646 java.
Databases. Not All Tables Are Created Equal Spreadsheets use tables to store data and formulas associated with that data The “meaning” of data is implicit.
1 Relational Databases and SQL. Learning Objectives Understand techniques to model complex accounting phenomena in an E-R diagram Develop E-R diagrams.
Unit 3 Conceptual Data Modeling. Key Concepts Conceptual data modeling process Classes and objects Attributes Identifiers, candidate keys, and primary.
Chapter 12 Entity-Relationship Modeling Pearson Education © 2009.
The Static Analysis Model Class Diagrams Prof. Hany H. Ammar, CSEE, WVU, and Dept. of Computer Science, Faculty of Computers and Information, Cairo University.
Chapter 3 Object Specification Languages Prof. Hyoung-Joo Kim OOPSLA Lab. Dept. of Computer Engineering Seoul National Univ.
Object Modeling (1) Chapter 3 (1) Part 1: Modeling Concepts Object-Oriented Modeling and Design Byung-Hyun Ha
DeSiamorePowered by DeSiaMore1 Database Management Systems (DBMS)  B. Computer Science and BSc IT Year 1.
Carnegie Mellon University © Robert T. Monroe Management Information Systems Data Modeling II – Relationships Management Information.
CS 405G: Introduction to Database Systems Lecture 2 : Database Design I.
Msigwaemhttp//:msigwaem.ueuo.com/1 Database Management Systems (DBMS)  B. Computer Science and BSc IT Year 1.
JAVA Classes Review. Definitions Class – a description of the attributes and behavior of a set of computational objects Constructor – a method that is.
PROG Object Oriented Programming II With Java PROG Object Oriented Programming II With Java Class Relationships.
Goals for Today 1  Multiton  maps  static factory methods.
Mixing Static and Non-static
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 7 Data Modeling Using the Entity- Relationship (ER) Model.
Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 1.
Database Systems – ER Diagrams EXAMPLE COMPANY DATABASE Requirements of the Company (oversimplified to illustrate) The company is organized into DEPARTMENTs.
The assignment expressions. The assignment operator in an assignment statement We have seen the assignment statement: Effect: var = expr; Stores the value.
Chapter 2 Data Modeling Using the Entity-Relationship (ER) Model Copyright © 2004 Pearson Education, Inc.
Copyright © 2013 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill/Irwin APPENDIX C DESIGNING DATABASES APPENDIX C DESIGNING DATABASES.
Data Modeling Using the Entity- Relationship (ER) Model.
Chapter 16 UML Class Diagrams.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 7 Data Modeling Using the Entity- Relationship (ER) Model.
Arrays-. An array is a way to hold more than one value at a time. It's like a list of items.
2 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel Data Models Why data models are important About the basic data-modeling.
Lecture 5 Entity Relationship Modeling
Object Oriented Programming Object and Classes Lecture 3 MBY.
Kyung Hee University Class Diagramming Notation OOSD 담당조교 석사과정 이정환.
BTS430 Systems Analysis and Design using UML Design Class Diagrams (ref=chapter 16 of Applying UML and Patterns)
Data Modeling Using the Entity- Relationship (ER) Model
Sixth Lecture ArrayList Abstract Class and Interface
Chapter 16 UML Class Diagrams.
بسم الله الرحمن الرحيم.
class PrintOnetoTen { public static void main(String args[]) {
Presentation transcript:

Mapping associations with and without attributes using: references (reference collections) association arrays

Outline Definition of an association Association symbols Mapping simple associations to Java Multiplicity Reference collections Associative arrays Exercises

Definition Association defines a relationship between classes of objects which allows one object instance to cause another to perform an action on its behalf.

Association symbols Associations in UML class diagrams - thin line connecting two classes The label are highly recommended (one or two words describing the association). For example „works_for” The black triangle is the reading direction. PersonCompany works_for 1 1..*

Association One-To-One class City { String name; public City(String name) { this.name = name; } class Country { City cap_city; public City Polska(String cap) { cap_city = new City(cap); return cap_city; }

Unidirectional Association class Person { Person p; BDate bdate; String name; public Person(String name, BDate bdate) { this.bdate=bdate; this.name = name; } class BDate { int month; int date; public BDate(int month, int date) { this.month = month; this.date = date; }

Association to itself public class Person { Person manager; Collection employees = new Vector(); public Person(Person o) { manager = m; } public void addEmplyees(Person p) { employees.add(p); }

Association with attributes class Person{ String personName; public Person(String name) { this.personName=name; } class Company{ String companyName; public Company(String name) { this.companyName=name; } public static class Employment{ Person employee; Company employer; int sal; public Employment(Person p, Company c, int salary) { employee = p; employer=c; sal = salary; }

Multiplicity The multiplicity of a binary association is placed at the end, specifies the number of target instances that may be associated with a single source instance across the given association CompanyEmployee 11..*

Multiplicity Multiplicity indicators 1 1, 2, 3,... 2, 3, 4,... 3, 4, 5 2, 4, 18 1, ? 0, 1 0, 1, 2, * 2..* 3-5 2,4, * * UMLmeanings

Array reference - collections Collection is any group of ordered items that has one or more properties in common. You can reference a single string inside an array by specifying the number of the reference that you want to extract in square brackets.

Association One-To-Two public class Bicycle { Wheel[] w = new Wheel[2]; public Bicycle(Wheel[] w) { if (w.length==2) System.out.println(„1 bicycle has 2 wheels”); } public class Wheel { public Wheel() {} }

Association One-To-Many public class Person { Collection cars = new Vector(); public Person() {} public void addCar(Car c) { c.assignOwner(this); cars.add(c); } public class Car { Person p; public Car(Person p) { this.p = p; } public void assignOwner(Person p) { this.p = p; }

Association Many-To-Many class Person { public Vector collectionCompany = new Vector(); String name; public Person(String name) { this.name = name; } void addCompany(Company c){ collectionCompany.add(c); } class Company { String name; public Company(String name) { this.name = name; } public Vector collectionEmplyees = new Vector(); void addEmployees(Person employee){ collectionEmplyees.add(employee); }

Associative Array An associative array is a data structure that stores pairs of keys and values. A value may be inserted or retrieved based on its key.

Associative Array public static void main(String[]args){ Company company = new Company("NewTech"); Person employee1 = new Person("Person A"); Person employee2 = new Person("Person B"); Hashtable companyEmployees = new Hashtable(); Vector employeesCollection = new Vector(); employeesCollection.add(employee1); employeesCollection.add(employee2); companyEmployees.put(company.companyName,employeesCollection); }

Associative Array public static void main(String args[]) { Division division1 = new Division("Division 1"); Division division2 = new Division("Division 2"); Person employee1 = new Person("Jan Nowak"); Person employee2 = new Person("Beata Kowalska"); Hashtable divisionEmployee = new Hashtable(); Hashtable employeeDivision= new Hashtable(); Vector employeeVec = new Vector(); Vector divisionVec = new Vector(); employeeVec.add(employee1); employeeVec.add(employee2); divisionVec.add(division1); divisionVec.add(division2); divisionEmployee.put(division1.nameDiv, employeeVec); employeeDivision.put(employee2.namePerson, divisionVec); }

Exercise 1 A language school asked you to create an IT system that stores information about its students, the language centers they are attending and courses that they take. Each course may have maximum 6 students. One student must have at lease one course. Create associations between the classes and implement it.

Exercise 2 A music store asked you to make an system that reports on CD sales. Create class diagrams, assisiations and implement the assosiation.

Exercise 3 A big insurance company needs a system to store information about their signed contracts and clients. A client may have a husband or a wife.

The End INCLUDED FILES OneToOne.java Directional.java Attribute.java OneToTwo.java OneToMany.java ManyToMany.java AssociativeArray.java AssociativeArray2.java Questions?