This document discusses aggregation and collection classes in Java. It introduces the concept of the "has-a" relationship between classes, where one class contains instances of other classes. It provides examples of classes like Employee that have attributes represented by other classes like PersonalDetails and JobDescription. It discusses encapsulation and exposing functionality through wrapper methods. It also introduces the concepts of ownership and aggregation vs composition. Finally, it discusses using arrays and collections to store and access groups of objects in a 1-to-many relationship.
Querying UML Class Diagrams - FoSSaCS 2012Giorgio Orsi
UML Class Diagrams (UCDs) are the best known class-based formalism for conceptual modeling. They are used by software engineers to model the intensional structure of a system in terms of classes, attributes and operations, and to express constraints that must hold for every instance of the system. Reasoning over UCDs is of paramount importance in design, validation, maintenance and system analysis; however, for medium and large software projects, reasoning over UCDs may be impractical. Query answering, in particular, can be used to verify whether a (possibly incomplete) instance of the system modeled by the UCD, i.e., a snapshot, enjoys a certain property. In this work, we study the problem of querying UCD instances, and we relate it to query answering under guarded Datalog +/-, that is, a powerful Datalog-based language for ontological modeling. We present an expressive and meaningful class of UCDs, named UCDLog, under which conjunctive query answering is tractable in the size of the instances.
The document discusses grouping elements and attributes in XML schemas. It describes several elements that can be used for grouping - sequence, group, choice, all, and attributeGroup. Sequence ensures elements appear in a specific order. Group allows elements to be reused. Choice selects a single element from multiple options. All uses child elements in any order. AttributeGroup groups reusable attributes. It also provides an example problem statement on grouping customer details from multiple branch offices.
The document discusses access modifiers in Java. There are four access modifiers: public, private, protected, and default. Public members are accessible everywhere, private only within the class, protected within subclasses and the package, and default only within the package. The document demonstrates how to use access modifiers with attributes and methods, including using getter and setter methods to access private attributes from other classes.
Basic Of C++ , Classes and Objects
1. A class defines a new data type that encapsulates data members and member functions. Classes allow for creating user-defined data types.
2. A class declaration specifies the data members and member functions of the class, while class definitions provide the implementation of member functions.
3. Objects are variables of a class type that allocate memory to store the class's data members. Member functions can access and manipulate the data members of an object.
The document provides an introduction to the Java programming language. It discusses Java's history and development. It describes key Java concepts like object-oriented programming, classes, objects, inheritance, polymorphism, and more. It also compares Java to C++ and outlines the typical Java development environment. The document includes a simple Java program example to demonstrate basic Java syntax.
The document provides an overview of lecture 03 on objects and classes in Java, including reviewing basic concepts, declaring and using classes, implementing inheritance, and discussing abstract classes and interfaces. It also includes examples of declaring classes, using constructors and methods, and implementing inheritance and polymorphism. The lecture aims to help students understand object-oriented concepts in Java like classes, objects, inheritance and polymorphism.
Querying UML Class Diagrams - FoSSaCS 2012Giorgio Orsi
UML Class Diagrams (UCDs) are the best known class-based formalism for conceptual modeling. They are used by software engineers to model the intensional structure of a system in terms of classes, attributes and operations, and to express constraints that must hold for every instance of the system. Reasoning over UCDs is of paramount importance in design, validation, maintenance and system analysis; however, for medium and large software projects, reasoning over UCDs may be impractical. Query answering, in particular, can be used to verify whether a (possibly incomplete) instance of the system modeled by the UCD, i.e., a snapshot, enjoys a certain property. In this work, we study the problem of querying UCD instances, and we relate it to query answering under guarded Datalog +/-, that is, a powerful Datalog-based language for ontological modeling. We present an expressive and meaningful class of UCDs, named UCDLog, under which conjunctive query answering is tractable in the size of the instances.
The document discusses grouping elements and attributes in XML schemas. It describes several elements that can be used for grouping - sequence, group, choice, all, and attributeGroup. Sequence ensures elements appear in a specific order. Group allows elements to be reused. Choice selects a single element from multiple options. All uses child elements in any order. AttributeGroup groups reusable attributes. It also provides an example problem statement on grouping customer details from multiple branch offices.
The document discusses access modifiers in Java. There are four access modifiers: public, private, protected, and default. Public members are accessible everywhere, private only within the class, protected within subclasses and the package, and default only within the package. The document demonstrates how to use access modifiers with attributes and methods, including using getter and setter methods to access private attributes from other classes.
Basic Of C++ , Classes and Objects
1. A class defines a new data type that encapsulates data members and member functions. Classes allow for creating user-defined data types.
2. A class declaration specifies the data members and member functions of the class, while class definitions provide the implementation of member functions.
3. Objects are variables of a class type that allocate memory to store the class's data members. Member functions can access and manipulate the data members of an object.
The document provides an introduction to the Java programming language. It discusses Java's history and development. It describes key Java concepts like object-oriented programming, classes, objects, inheritance, polymorphism, and more. It also compares Java to C++ and outlines the typical Java development environment. The document includes a simple Java program example to demonstrate basic Java syntax.
The document provides an overview of lecture 03 on objects and classes in Java, including reviewing basic concepts, declaring and using classes, implementing inheritance, and discussing abstract classes and interfaces. It also includes examples of declaring classes, using constructors and methods, and implementing inheritance and polymorphism. The lecture aims to help students understand object-oriented concepts in Java like classes, objects, inheritance and polymorphism.
The document provides an introduction to object-oriented programming concepts in Java, including objects, classes, encapsulation, inheritance, polymorphism, and constructors. It defines key OOPs concepts such as a class acting as a blueprint for an object. Features like data hiding, abstraction, encapsulation, and different types of inheritance relationships are explained. The differences between method overloading and overriding are highlighted. Default and parameterized constructors are demonstrated with examples.
How to write you first class in c++ object oriented programmingSyed Faizan Hassan
The document discusses how to write a first class in C++ using object-oriented programming. It explains that a class defines functions and variables and is like a blueprint for creating objects. An object is an instance of a class that stores values and allows access to class functions. The document provides an example class for calculating the sum of two numbers by getting input, processing the calculation, and outputting the result. It demonstrates creating an object of the class in the main function and calling the class functions through the object.
Collection Framework in Java | Generics | Input-Output in Java | Serializatio...Sagar Verma
Collection Framework in Java,Generics,Input-Output in Java,Serialization,Inner Classes
Collection Framework in Java
The Collections Framework - Set Interface- List Interface - Map Interface - Queue Interface -Sorting collections using utility methods
equals () and hash Code contract in Java collections
Overriding equals and hash Code methods in Java
Generics
Generics for Collections, class and methods
Input-Output in Java
What is a stream? ,Bytes vs. Characters, Java IO API ,Reading a file; writing to a file using various APIs
Reading User input from console , PrintWriter Class
Serialization
Object Serialization , Serializable Interface , De-Serializable
Inner Classes
Inner Classes ,Member Classes, Local Classes, Anonymous Classes, Static Nested Classes
Lesson 2 introduces key concepts of the Java programming language including basic syntax, class definitions, methods, and variables. The document provides examples to demonstrate Java naming conventions, class structure with modifiers and methods, and how Java code is compiled and run. It also describes packages and how they are used to organize related classes and avoid naming conflicts in Java programs.
This document discusses classes and objects in C++. It defines a class as a collection of related data and functions under a single name. A class is a user-defined type that combines data representation and methods for manipulating that data into a single unit. Objects are instances of a class - variables that are declared based on a class type. The document covers defining classes, declaring objects, accessing class members, arrays within classes, access modifiers like public, private and protected, static class members, inline functions, friend functions and classes.
Classes and objects allow bundling of related data and functions. An object is an instance of a class that contains the class's data members and can access its member functions. Classes improve on procedural programming by avoiding issues when data structures change. A class defines the data types and functions for a user-defined type using a class name, data members, and member functions. Objects are instances of classes that hold separate copies of class data. Access specifiers like public, private, and protected control access to class members.
Classes in C++ allow developers to combine data and functions that operate on that data into logical units called objects. A class defines the form and behavior of objects, while objects are individual instances of a class. Some key points:
- Classes contain data fields called data members and functions called member functions.
- Objects are instantiated from classes and allocate memory to store values for an instance.
- Access specifiers like public, private, and protected determine which parts of a class are accessible from outside the class.
- Classes can contain static members that are shared across all objects of the class rather than being unique to each object.
The document discusses structures and classes in C++. It explains that structures in C++ allow grouping of related data items but do not provide data hiding. Classes in C++ address this limitation by allowing data and functions as members, and designating some members as private. The key aspects of a class include its declaration with data and function members, creation of objects from the class, and accessing members using objects and dot operator (for public members) or within class functions (for private members). Static members are also discussed which are shared among all class objects.
This document discusses methods in object-oriented programming. It explains two types of methods: instance methods and class methods. Instance methods require an object to invoke, while class methods do not. The document also covers constructors, which are special methods used to initialize objects. Constructors have the same name as the class and do not specify a return type. Default constructors are automatically generated if no other constructors are defined. Multiple constructors can be defined using constructor overloading.
The document discusses XML DOM objects and how to use them to validate XML documents against schemas, and apply style sheets to XML documents. It identifies key DOM objects like Document, Element, Node, and their properties and methods. It also describes using the XMLSchemaCache object to validate XML files against schemas, and the XSLTemplate and XSLProcessor objects to apply XSLT style sheets to XML documents.
The document provides an overview of the Java Persistence API (JPA) and how to use it for object-relational mapping. It discusses mapping entities to database tables, relationships like many-to-one and one-to-many, and managing persistence with an EntityManager. The key aspects covered are configuring JPA, writing entity classes, performing CRUD operations, querying entities, and dealing with detached and merged states.
The document discusses classes and objects in object-oriented programming. It defines what a class is, how classes are declared with public and private members, and how objects are instantiated from classes. It also describes defining member functions inside and outside of classes, and the use of static class members and friend functions.
Classes are user-defined data types that contain data members and member functions. Data members are variables inside the class and member functions are functions inside the class. Classes define common characteristics and behaviors for objects instantiated from the class. Objects are instances of a class that hold the class's data members and allow member functions to work on the object's data. Constructors initialize objects and destructors release the memory of objects when they go out of scope.
The document describes adding object-oriented programming capabilities to the Euclideus programming language. It had previously only supported procedural programming. Both class-based and prototype-based object orientation are now supported. Key elements like classes, objects, inheritance, and encapsulation are defined. Classes serve as recipes for creating object instances and can also have their own static members. Objects gain data and methods via their class.
This document discusses classes and objects in C++. It defines a class as a user-defined data type that implements an abstract object by combining data members and member functions. Data members are called data fields and member functions are called methods. An abstract data type separates logical properties from implementation details and supports data abstraction, encapsulation, and hiding. Common examples of abstract data types include Boolean, integer, array, stack, queue, and tree structures. The document goes on to describe class definitions, access specifiers, static members, and how to define and access class members and methods.
This document discusses classes and objects in C++. It begins with an introduction to classes, noting that a class binds data and methods together and acts as a template for creating objects. It then covers key aspects of classes like characteristics, format, defining a class type, implementing class methods, and introducing objects. Objects are instances of a class that have both data and associated methods. The document provides examples of declaring and initializing objects of a Rectangle class. It concludes with some reasons for using the object-oriented programming paradigm in C++, including simplifying programming, interfaces, information hiding, and software reuse.
The document discusses key concepts of object-oriented programming including objects, classes, inheritance, polymorphism, encapsulation, and abstraction. It provides examples of constructors, method overloading and overriding, interfaces, and packages in Java.
This document provides an introduction to object-oriented programming concepts in Java including objects, classes, inheritance, polymorphism, and more. It defines key terms like class, object, state, behavior, identity. It also discusses the differences between objects and classes and provides examples of declaring classes and creating objects in Java. Methods, constructors, and initialization of objects are explained. Inheritance, method overriding, and polymorphism are defined along with examples.
Object Oriented Programming is revisited. It is assumed that students know OO languages so this is more of a review. We will cover concepts such as encapsulation, interfaces and polymorphism. These are important concepts that students must understand in order to write flexible and lasting code. We look at several design principles.
We also look at software design and take an example from a video games.
In this lecture we will also reveal the secret of programming which all good programmers must know.
C# is an object-oriented programming language created by Microsoft. It was created by a team led by Anders Hejlsberg with the goal of combining the best aspects of existing languages and improving upon them. C# code is compiled into an intermediate language called IL, which is then executed by the Common Language Runtime (CLR). Key concepts of object-oriented programming in C# include classes, objects, abstraction, encapsulation, polymorphism, and inheritance. Classes define the attributes and behaviors of objects, and objects are instances of classes.
C# is an object-oriented programming language created by Microsoft that can be used to create a variety of applications. The key steps in executing a C# program are compilation, where source code is converted to bytecode, and execution, where the bytecode is converted to machine code and run. C# supports important object-oriented concepts like classes, objects, inheritance, polymorphism, abstraction and encapsulation. Classes define the attributes and behaviors of objects, and objects are instantiated from classes. Constructors initialize new objects.
1) Object oriented databases were developed to directly represent complex objects from emerging applications that could not be effectively modeled in the relational model. 2) Embedded SQL allows SQL queries to be embedded within a general purpose programming language to access and manipulate database objects. 3) Object oriented database management systems can be either pure object oriented programming languages with persistence or extend relational databases with object oriented features as defined in the SQL3 standard.
The document provides an introduction to object-oriented programming concepts in Java, including objects, classes, encapsulation, inheritance, polymorphism, and constructors. It defines key OOPs concepts such as a class acting as a blueprint for an object. Features like data hiding, abstraction, encapsulation, and different types of inheritance relationships are explained. The differences between method overloading and overriding are highlighted. Default and parameterized constructors are demonstrated with examples.
How to write you first class in c++ object oriented programmingSyed Faizan Hassan
The document discusses how to write a first class in C++ using object-oriented programming. It explains that a class defines functions and variables and is like a blueprint for creating objects. An object is an instance of a class that stores values and allows access to class functions. The document provides an example class for calculating the sum of two numbers by getting input, processing the calculation, and outputting the result. It demonstrates creating an object of the class in the main function and calling the class functions through the object.
Collection Framework in Java | Generics | Input-Output in Java | Serializatio...Sagar Verma
Collection Framework in Java,Generics,Input-Output in Java,Serialization,Inner Classes
Collection Framework in Java
The Collections Framework - Set Interface- List Interface - Map Interface - Queue Interface -Sorting collections using utility methods
equals () and hash Code contract in Java collections
Overriding equals and hash Code methods in Java
Generics
Generics for Collections, class and methods
Input-Output in Java
What is a stream? ,Bytes vs. Characters, Java IO API ,Reading a file; writing to a file using various APIs
Reading User input from console , PrintWriter Class
Serialization
Object Serialization , Serializable Interface , De-Serializable
Inner Classes
Inner Classes ,Member Classes, Local Classes, Anonymous Classes, Static Nested Classes
Lesson 2 introduces key concepts of the Java programming language including basic syntax, class definitions, methods, and variables. The document provides examples to demonstrate Java naming conventions, class structure with modifiers and methods, and how Java code is compiled and run. It also describes packages and how they are used to organize related classes and avoid naming conflicts in Java programs.
This document discusses classes and objects in C++. It defines a class as a collection of related data and functions under a single name. A class is a user-defined type that combines data representation and methods for manipulating that data into a single unit. Objects are instances of a class - variables that are declared based on a class type. The document covers defining classes, declaring objects, accessing class members, arrays within classes, access modifiers like public, private and protected, static class members, inline functions, friend functions and classes.
Classes and objects allow bundling of related data and functions. An object is an instance of a class that contains the class's data members and can access its member functions. Classes improve on procedural programming by avoiding issues when data structures change. A class defines the data types and functions for a user-defined type using a class name, data members, and member functions. Objects are instances of classes that hold separate copies of class data. Access specifiers like public, private, and protected control access to class members.
Classes in C++ allow developers to combine data and functions that operate on that data into logical units called objects. A class defines the form and behavior of objects, while objects are individual instances of a class. Some key points:
- Classes contain data fields called data members and functions called member functions.
- Objects are instantiated from classes and allocate memory to store values for an instance.
- Access specifiers like public, private, and protected determine which parts of a class are accessible from outside the class.
- Classes can contain static members that are shared across all objects of the class rather than being unique to each object.
The document discusses structures and classes in C++. It explains that structures in C++ allow grouping of related data items but do not provide data hiding. Classes in C++ address this limitation by allowing data and functions as members, and designating some members as private. The key aspects of a class include its declaration with data and function members, creation of objects from the class, and accessing members using objects and dot operator (for public members) or within class functions (for private members). Static members are also discussed which are shared among all class objects.
This document discusses methods in object-oriented programming. It explains two types of methods: instance methods and class methods. Instance methods require an object to invoke, while class methods do not. The document also covers constructors, which are special methods used to initialize objects. Constructors have the same name as the class and do not specify a return type. Default constructors are automatically generated if no other constructors are defined. Multiple constructors can be defined using constructor overloading.
The document discusses XML DOM objects and how to use them to validate XML documents against schemas, and apply style sheets to XML documents. It identifies key DOM objects like Document, Element, Node, and their properties and methods. It also describes using the XMLSchemaCache object to validate XML files against schemas, and the XSLTemplate and XSLProcessor objects to apply XSLT style sheets to XML documents.
The document provides an overview of the Java Persistence API (JPA) and how to use it for object-relational mapping. It discusses mapping entities to database tables, relationships like many-to-one and one-to-many, and managing persistence with an EntityManager. The key aspects covered are configuring JPA, writing entity classes, performing CRUD operations, querying entities, and dealing with detached and merged states.
The document discusses classes and objects in object-oriented programming. It defines what a class is, how classes are declared with public and private members, and how objects are instantiated from classes. It also describes defining member functions inside and outside of classes, and the use of static class members and friend functions.
Classes are user-defined data types that contain data members and member functions. Data members are variables inside the class and member functions are functions inside the class. Classes define common characteristics and behaviors for objects instantiated from the class. Objects are instances of a class that hold the class's data members and allow member functions to work on the object's data. Constructors initialize objects and destructors release the memory of objects when they go out of scope.
The document describes adding object-oriented programming capabilities to the Euclideus programming language. It had previously only supported procedural programming. Both class-based and prototype-based object orientation are now supported. Key elements like classes, objects, inheritance, and encapsulation are defined. Classes serve as recipes for creating object instances and can also have their own static members. Objects gain data and methods via their class.
This document discusses classes and objects in C++. It defines a class as a user-defined data type that implements an abstract object by combining data members and member functions. Data members are called data fields and member functions are called methods. An abstract data type separates logical properties from implementation details and supports data abstraction, encapsulation, and hiding. Common examples of abstract data types include Boolean, integer, array, stack, queue, and tree structures. The document goes on to describe class definitions, access specifiers, static members, and how to define and access class members and methods.
This document discusses classes and objects in C++. It begins with an introduction to classes, noting that a class binds data and methods together and acts as a template for creating objects. It then covers key aspects of classes like characteristics, format, defining a class type, implementing class methods, and introducing objects. Objects are instances of a class that have both data and associated methods. The document provides examples of declaring and initializing objects of a Rectangle class. It concludes with some reasons for using the object-oriented programming paradigm in C++, including simplifying programming, interfaces, information hiding, and software reuse.
The document discusses key concepts of object-oriented programming including objects, classes, inheritance, polymorphism, encapsulation, and abstraction. It provides examples of constructors, method overloading and overriding, interfaces, and packages in Java.
This document provides an introduction to object-oriented programming concepts in Java including objects, classes, inheritance, polymorphism, and more. It defines key terms like class, object, state, behavior, identity. It also discusses the differences between objects and classes and provides examples of declaring classes and creating objects in Java. Methods, constructors, and initialization of objects are explained. Inheritance, method overriding, and polymorphism are defined along with examples.
Object Oriented Programming is revisited. It is assumed that students know OO languages so this is more of a review. We will cover concepts such as encapsulation, interfaces and polymorphism. These are important concepts that students must understand in order to write flexible and lasting code. We look at several design principles.
We also look at software design and take an example from a video games.
In this lecture we will also reveal the secret of programming which all good programmers must know.
C# is an object-oriented programming language created by Microsoft. It was created by a team led by Anders Hejlsberg with the goal of combining the best aspects of existing languages and improving upon them. C# code is compiled into an intermediate language called IL, which is then executed by the Common Language Runtime (CLR). Key concepts of object-oriented programming in C# include classes, objects, abstraction, encapsulation, polymorphism, and inheritance. Classes define the attributes and behaviors of objects, and objects are instances of classes.
C# is an object-oriented programming language created by Microsoft that can be used to create a variety of applications. The key steps in executing a C# program are compilation, where source code is converted to bytecode, and execution, where the bytecode is converted to machine code and run. C# supports important object-oriented concepts like classes, objects, inheritance, polymorphism, abstraction and encapsulation. Classes define the attributes and behaviors of objects, and objects are instantiated from classes. Constructors initialize new objects.
1) Object oriented databases were developed to directly represent complex objects from emerging applications that could not be effectively modeled in the relational model. 2) Embedded SQL allows SQL queries to be embedded within a general purpose programming language to access and manipulate database objects. 3) Object oriented database management systems can be either pure object oriented programming languages with persistence or extend relational databases with object oriented features as defined in the SQL3 standard.
This document discusses abstract classes and interfaces in Java. It introduces abstract classes using a drawing package example, showing how abstract classes like Shape can be extended by classes like Rectangle and Circle. Interfaces are also introduced, explaining that they specify what an object can do without defining how. Classes can implement multiple interfaces to take on those required behaviors.
The document provides an overview of the relational data model and relational algebra. It discusses how the relational model represents data using tables of attribute-value pairs and allows standard logical operations. Key concepts covered include the relational operations of projection, selection, join, union, difference, and divide. SQL is introduced as the standard language for querying and manipulating relational data using these algebraic operations.
1) Object-oriented programming (OOP) uses classes and objects to organize code and data to make it more modular and reusable. Many popular languages like Java, C++, and C# use OOP.
2) A class defines the data (properties) and behavior (methods) of an object. Constructors are used to create objects from classes.
3) To access data and methods of an object, it must first be instantiated by using the new keyword followed by the class name, then its methods and properties can be called.
Defining class
Defining member functions
Static data members
Static member functions
Private data members
Public member functions
Arrays of objects
Objects as a function arguments
Constructors and destructors
Types of constructors
Handling of multiple constructors, destructors.
Class is a blueprint for creating objects that share common attributes and behaviors. A class defines the data and methods that describe the object. Classes in Java can contain data members, methods, constructors, nested classes, and interfaces. Objects are instances of classes that occupy memory at runtime and can access class members like variables and methods. Constructors initialize an object when it is created and have the same name as the class. The this keyword refers to the current object in a method or constructor. Command line arguments can be passed to a program as strings and accessed via the args parameter in the main method.
The basic building blocks of the object model are
1 Objects
2 Literals
An object has four characteristics
Identifier: unique system-wide identifier
Name: unique within a particular database and/or program; it is optional
Lifetime: persistent vs. transient
Structure: specifies how object is constructed by the type constructor and whether it is an atomic object
This lecture introduces Java programming and covers: the Java Virtual Machine; object oriented concepts like classes and instances; the structure of a Java program; and using the Scanner class for input/output. Key topics are compiling Java code, executing bytecode on the JVM, and the basics of classes, methods, and objects.
The document discusses a lecture on object-oriented programming. It covers key topics like classes, objects, fields, methods, constructors, and creating objects from classes. It provides examples of how to define classes with fields, methods, and constructors. It also explains how to compile and run a simple Java program with a main method.
This class is abstract but it does not provide implementation of abstract method print(). An abstract class must be subclassed and the abstract methods must be implemented in the subclass. We cannot create an object of an abstract class directly, it has to be through its concrete subclass.
This document provides an introduction to object-oriented databases (OODBMS). It discusses key concepts like objects having an identity, structure and type constructor. An OODBMS allows for complex object structures, encapsulation of operations, inheritance and relationships between objects using object identifiers. It provides advantages over traditional databases for applications requiring complex data types and application-specific operations.
This document provides an introduction to object-oriented programming concepts. It discusses breaking programs down into objects rather than procedures, with each object having descriptive data as attributes and associated actions as methods. It provides an example class definition for a Person object, showing how to define attributes like age and methods like saying one's age. The document also covers key concepts like classes versus objects, instantiation, and calling methods on objects from outside the class.
- The document discusses object-oriented programming concepts like classes, objects, methods, and constructors.
- A class defines the attributes and behaviors of an object, while an object is an instance of a class. Methods define behaviors that objects can perform.
- Constructors initialize an object's attributes when it is created. Multiple constructors with different parameters allows initializing objects in different ways.
- Accessor methods like getters allow retrieving an object's attribute values, while mutator methods like setters allow modifying attribute values.
- The examples demonstrate defining classes with attributes, methods, and constructors, as well as creating objects and calling methods on them.
This document provides an introduction to object-oriented programming concepts. It discusses breaking programs down into objects rather than procedures, with each object having descriptive data as attributes and associated actions as methods. It provides an example class definition for a Person object, with attributes like age and methods like saying one's age. The document also covers other key concepts like instantiating objects, calling methods, and defining a default constructor.
The document provides instructions for printing PowerPoint lectures in black and white to save printer ink. It advises users to select "File > Print", then change the "Color" setting to "Pure Black and White" to print without using color ink.
This document discusses object-oriented analysis and design (OOAD). It introduces key OOAD concepts like classes, objects, abstraction, encapsulation, inheritance, polymorphism, and associations. It explains that OOAD implements object-oriented analysis to develop an object model of the problem, object-oriented design to develop a model of the solution, and object-oriented programming to develop the model using an OO language. The document also discusses using the Unified Modeling Language (UML) for OOAD, with examples of use case diagrams and class diagrams. It provides external readings on OOAD and gives homework questions related to analyzing a class diagram for an elevator system.
Object Query Language is a query language standard for object-oriented databases modeled after SQL. OQL was developed by the Object Data Management Group. Because of its overall complexity nobody has ever fully implemented the complete OQL.
Similar to 08 aggregation and collection classes (20)
This document introduces a module on programming concepts in C++. The module will cover object-oriented programming principles, C++ basics, classes, inheritance, pointers, and more. Students will learn to apply OOP to model real-world systems. Their knowledge will be assessed through a final exam and group project, both testing their ability to explain and apply core OOP concepts and develop class structures.
The document summarizes and compares several major object-oriented programming languages: Smalltalk, C++, Eiffel, and Java. Smalltalk was designed for interactive use and has a fully integrated development environment, while C++ was designed for production use and has less integration. Eiffel focuses on ensuring code correctness but had poor tooling. Java became popular for web development due to its portability and is expected to further object-oriented adoption.
This chapter discusses software design patterns, including why they evolved to capture recurring design solutions, defines a design pattern as describing communicating objects and classes that solve general problems, and describes fundamental GRASP patterns that assign responsibilities to experts, creators, or controllers to achieve high cohesion and low coupling.
This chapter discusses dynamic modeling techniques used to describe the behavior of object-oriented systems. It introduces sequence diagrams and collaboration diagrams, which show how objects interact and communicate through messages. Sequence diagrams focus on the time-ordering of messages while collaboration diagrams emphasize the relationships between objects. The chapter also covers different types of messages and events that can be depicted in dynamic models.
This chapter introduces activity diagrams and discusses where they are used. Activity diagrams can model workflows, operations, and dynamic aspects of a system. They contain activities, transitions, synchronization bars, and decision activities. Activity diagrams are suitable for analyzing use cases, understanding workflow, and modeling multithreaded applications. They are not suitable for showing object collaboration or lifetime behavior.
This chapter introduces state diagrams and their components. It discusses how state diagrams describe the states of an object and transitions between states triggered by events. It covers initial and final states, actions, activities, and different types of events. The chapter also discusses transitions between states and the use of guard conditions. Finally, it introduces concepts of nested and concurrent states.
Class diagrams using UML can model the static view of a system by showing how classes are related through relationships like association and generalization. The chapter introduces class diagram notation and discusses how to identify problem domain classes and the different relationships that can exist between classes like association, aggregation, composition, and generalization. It also covers how to model classes, attributes, operations, and relationships in UML class diagrams.
The document summarizes a chapter about use case modeling. It describes use cases and actors, relationships between use cases, and use case descriptions. Use case modeling involves identifying functional requirements, drawing diagrams showing actors and use cases, and writing use case descriptions in a conversational style to document interactions between actors and the system. Relationships like include, extend, and generalization are used to show how use cases relate to each other.
This document introduces a module on programming concepts in C++. The module will cover object-oriented programming principles, C++ basics, classes and objects, inheritance, pointers, and more. Students will learn to apply OOP to model real-world systems. Their knowledge will be assessed through a final exam and group coursework assignments focusing on programming and class design.
This document discusses reading from and writing to files in Java programs. It explains how to open a file using a Scanner or PrintWriter object, read/write data using methods like next() and println(), and close the file when finished. It recommends storing file data in memory structures, processing it, then writing the results back to improve efficiency over sequential file access. Proper file handling and exception handling are also emphasized.
This document introduces GUI development in Java using the Abstract Window Toolkit (AWT) and Java Foundation Classes (JFC). It discusses containers, layout managers, events, and event handling. The key GUI components introduced are JFrame for top-level windows, JPanel for grouping components, and using layout managers like BorderLayout and GridLayout to position components. It also covers adding event listeners to components to handle user interactions.
The document discusses exception handling in Java. It defines an exception as an event that disrupts normal program flow, such as dividing by zero. Exceptions are handled using try, catch, and finally blocks. Catch blocks handle specific exception types. Checked exceptions must be handled, while unchecked exceptions do not require handling but can cause program termination. The document provides examples of exception handling for input/output errors and file processing.
1. Aggregation and Collection Classes
OOSSE - Programming with Java
Lecture 7
Dec 21, 2012 OOSSE - Java Lecture 7 1
2. Objectives
In this lecture, we will:
• Discuss the Has-A relationship
• Define classes that contain instances of other classes
• Introduce concept of ownership of objects
• Review the UML class diagrams used to indicate the Has-
A relationship
• Introduce Collections and the Java Collections API
• Discuss Generics
Dec 21, 2012 OOSSE - Java Lecture 7 2
3. The HAS-A Relationship
• The classes that we have built so far represent fairly
simple objects
– the member variables are instances of simple data types
• The approach in OOP is a building block approach
• Once we have built simple classes these can be used as
the basis of more complicated classes
• The simplest relationship is where a new class has
member variables that are instances of other classes
– the HAS-A relationship
Dec 21, 2012 OOSSE - Java Lecture 7 3
4. The HAS-A Relationship
• A class is used to model and encapsulate an object
• Member variables represent the attributes of an object
• In a complex model the attributes may themselves be
objects rather than primitive data types
• Consider modelling a vehicle, we may think of the
components as objects
– a vehicle has wheels; the wheels are objects
– a vehicle has an engine; the engine is an object
• The term HAS-A is used to describe the relationship
between the vehicle class and the engine class
Dec 21, 2012 OOSSE - Java Lecture 7 4
5. An Employee Class
• In modelling an employee we may start with a class that
has the following member variables:
– a payroll number, a set of personal details, a job description
• The set of personal details may be best modelled using
another class that has member variables such as:
– name, age, email
• The job description may be another class with member
variables such as:
– title, department, grade
Dec 21, 2012 OOSSE - Java Lecture 7 5
6. An Employee Class
• The employee class
– Has a employee number
– Has a set of personal details
– Has a job description
Dec 21, 2012 OOSSE - Java Lecture 7 6
7. PersonalDetails
public class PersonalDetails {
private String Fullname;
private int age;
private String email;
public PersonalDetails(String n, int a, String e)
{
Fullname = n;
age = a;
email = e;
}
public String toString()
{
String s = "Fullname: " + Fullname + " age: " + age +
" email: " + email;
return s;
}
Dec 21, 2012 OOSSE - Java Lecture 7 7
8. PersonalDetails
public String getFullname()
{
return Fullname;
}
public String getEmail()
{
return email;
}
public int getAge()
{
return age;
}
}
Dec 21, 2012 OOSSE - Java Lecture 7 8
9. JobDescription
public class JobDescription {
public JobDescription(String t, String d, int g) {
title = t;
department = d;
grade = g;
}
public String toString()
{
String s = "Job title: " + title + " Grade: " +
grade + " Department: " + department ;
return s;
}
Dec 21, 2012 OOSSE - Java Lecture 7 9
10. JobDescription (continued)
public String getTitle()
{
return title;
}
String title;
String department;
int grade;
}
Dec 21, 2012 OOSSE - Java Lecture 7 10
11. Employee
public class Employee {
private int payrollNumber;
private PersonalDetails lnkPersonalDetails;
private JobDescription lnkJobDescription;
public Employee(PersonalDetails d, JobDescription j, int n)
{
lnkPersonalDetails = d;
lnkJobDescription = j;
payrollNumber = n;
}
Dec 21, 2012 OOSSE - Java Lecture 7 11
12. Employee (continued)
public String toString()
{
String s = "Employee Detailsn" +
lnkPersonalDetails.toString() + "n" +
lnkJobDescription.toString();
return s;
}
}
Dec 21, 2012 OOSSE - Java Lecture 7 12
14. TestEmployee
public class TestEmployee {
// Driver class used to test the Employee class
public static void main(String [ ] args)
{
PersonalDetails fredPD = new PersonalDetails("Fred Bloggs",
34, "fred@xyz");
JobDescription fredJD = new JobDescription("Plumber",
"maintenance",3);
Employee fred = new Employee(fredPD,fredJD,1001);
System.out.println(fred);
}
}
Dec 21, 2012 OOSSE - Java Lecture 7 14
15. TestEmployee
• The output from the test would be:
Employee Details
Fullname: Fred Bloggs age: 34 email: fred@xyz
Job title: Plumber Grade: 3 Department: maintenance
Dec 21, 2012 OOSSE - Java Lecture 7 15
16. Encapsulation and the HAS-A
Relationship
• Consider a class that contains member variables that are
instances of other classes
• How is access to the functionality of the contained classes
exposed to users of the containing class?
• Option 1 - make the member variables public giving direct
access to the public members of the contained classes
– Breaks encapsulation
• Option 2 - make the member variables private and write
wrapper functions that call the member functions of the
contained classes
– A more object oriented approach
Dec 21, 2012 OOSSE - Java Lecture 7 16
17. Exposing the Name of an Employee
• Suppose the name of an employee is required
• How can a method to provide the name of an employee
be written?
• The name is stored in the PersonalDetails object
– private String Fullname
– Accessible using the getFullname() method
• Employee can be considered as a wrapper class that
takes advantage of the functionality in PersonalDetails
– The user of the Employee class does not need to know that
an object of type PersonalDetails is used
– Indeed a user of Employee should not have to know!
Dec 21, 2012 OOSSE - Java Lecture 7 17
18. The name of an Employee
• Consider the following code :
public String getName()
{
// delegate to the PersonalDetails object
return lnkPersonalDetails.getFullname();
}
• This is a method of the Employee class
Dec 21, 2012 OOSSE - Java Lecture 7 18
19. The name and Job of an Employee
• Suppose the name and job title of an employee are required
as a string
public String getNameAndJob ()
{
// use methods of PersonalDetails and JobDescription
String s = getName() + " " + lnkJobDescription.getTitle();
return s;
}
• This is a method of the employee class
Dec 21, 2012 OOSSE - Java Lecture 7 19
20. Constructors Revisited
• Consider the constructor of an Employee:
public Employee(PersonalDetails d, JobDescription j, int n)
{
lnkPersonalDetails = d;
lnkJobDescription = j;
payrollNumber = n;
}
• The constructor receives two objects and an integer
– The details and job description are constructed outside of
the employee class
Dec 21, 2012 OOSSE - Java Lecture 7 20
21. An Alternative Constructor
public Employee(String n, int a, String e,
String t, String d, int g, int num)
{
lnkPersonalDetails = new PersonalDetails(n,a,e);
lnkJobDescription = new JobDescription(t,d,g);
payrollNumber = num;
}
• In this version the objects representing the details and job
are constructed inside the employee class
• Constructors and other methods can be overloaded
– both versions can exist in the same class
Dec 21, 2012 OOSSE - Java Lecture 7 21
22. Ownership
• Which of the two versions of the constructor is the right
one to choose?
• This is a design issue
• In the first example the employee does not own the
objects that describe the personal details and the job
– The employee is not responsible for their construction
• In the second example the employee owns the objects
– The objects were constructed inside the Employee class
• The design decision is based upon whether or not the
objects that describe the personal details and the job
NEED to exist outside of an employee
Dec 21, 2012 OOSSE - Java Lecture 7 22
23. What next?
• We have seen a class to represent an employee that
contains instances of other classes
– has-a relationship
• How do we go about storing and accessing a group of
employees?
• We will now look at two possible ways of storing groups of
objects:
– using arrays
– using collections
Dec 21, 2012 OOSSE - Java Lecture 7 23
24. Aggregation
• Aggregation describes the case where an object of one class
contains objects of another class
– The Has-A relationship describe earlier
• Consider a team made up of several players:
Team Player
1 *
Dec 21, 2012 OOSSE - Java Lecture 7 24
25. Composition
• Composition is a stronger form of aggregation
– The contained objects do not have an existence independent of
the container
– Construction of the objects is the responsibility of the container
• Consider a house with several walls:
House Wall
1 *
Dec 21, 2012 OOSSE - Java Lecture 7 25
26. Representing Aggregation
• The simplest way to represent a 1 to many aggregation is
to use an array
• The container class manages the collection of objects
– an array is used to hold the collection
• Arrays were introduced in an earlier lecture
• Consider the team of players discussed earlier
• The Team class might have a member variable that is an
array of Players
public class Team
{
private Player thePlayers[] ;
…
Dec 21, 2012 OOSSE - Java Lecture 7 26
27. Team Example
• In this example a class is used to represent a team of players
Note how together indicates the aggregation
Dec 21, 2012 OOSSE - Java Lecture 7 27
28. Player
public class Player {
private String name;
private String position;
private int age;
public Player (String s, String p, int a)
{
name = s;
position = p;
age = a;
}
Dec 21, 2012 OOSSE - Java Lecture 7 28
29. Player (continued)
public String toString()
{
String s = "Name: " + name + " Position: " +
position + " Age: " + age;
return s;
}
public String getPosition()
{
return position;
}
public int getAge()
{
return age;
}
}
Dec 21, 2012 OOSSE - Java Lecture 7 29
30. Team
public class Team {
private Player [] thePlayers;
private int numPlayers;
private int maxPlayers;
private String teamName;
public Team (String name, int num)
{
teamName = name;
maxPlayers = num;
numPlayers = 0;
thePlayers = new Player [maxPlayers];
}
Dec 21, 2012 OOSSE - Java Lecture 7 30
31. Team (continued)
public boolean addPlayer( Player newPlayer )
{
// add another player to the team if the team is not full
if ( numPlayers == maxPlayers )
{
// the team is full, player cannot be added
return false;
}
else
{
// add player to the team
thePlayers[numPlayers] = newPlayer;
numPlayers++;
return true;
}
}
Dec 21, 2012 OOSSE - Java Lecture 7 31
32. Team (continued)
public void outputTeamDetails()
{
System.out.println("Team name: " + teamName );
//output each player in turn
System.out.println("The players:");
for( int i=0; i < numPlayers; ++i)
{
System.out.println(thePlayers[i]);
}
}
}
Dec 21, 2012 OOSSE - Java Lecture 7 32
33. TestTeam
public class TestTeam {
// Driver class to test the Team class
public static void main(String []args)
{
//Construct a few players
Player dave = new Player("Dave","Goalkeeper",24);
Player joe = new Player("Joe", "Striker", 21);
Player andy = new Player("Andy", "Defender", 29);
Team rovers = new Team("Rovers",5);
rovers.addPlayer(dave);
rovers.addPlayer(joe);
rovers.addPlayer(andy);
rovers.outputTeamDetails();
}
}
Dec 21, 2012 OOSSE - Java Lecture 7 33
34. Collections
• Java supports several collection classes
• The simplest to use is the vector
– the vector is like a dynamic array
• The vector class exists in the util namespace:
– import java.util.*;
• Constructing a vector is easy:
– Vector <Player> myVector = new Vector <Player> () ;
• Here the initial size of the vector is not specified
– the vector will grow as necessary
• The constructor is overloaded:
– Vector <Player> (int size)
– Vector <Player> (int size, int incr)
Dec 21, 2012 OOSSE - Java Lecture 7 34
35. Using the Vector Class
• The capacity of the vector can be set to an initial value
using the member function ensureCapacity
– myVector.ensureCapacity(20);
– Sets the minimum size of the vector to 20 items
• The method addElement can be used to add data to a
vector:
– Player andy = new Player("Andy", "Defender", 29);
– myVector.addElement (andy);
– inserts andy at the end of the current data
• Vectors hold Objects
– Object is the base class of all objects
– A player is an Object
Dec 21, 2012 OOSSE - Java Lecture 7 35
36. Using the Vector Class
• The method elementAt can be used to get data out of the
vector:
– Player thePlayer;
– thePlayer = myVector.elementAt(3) ;
• In older versions of Vector only Objects were held
• An Object would be returned by the method
• As it is known that Players are stored in the vector then
the object would be cast to a Player
– Then the methods of the Player class can be used
• If objects of more than one type have been added to the
vector then instanceof of could be used to check the type:
– if ( myVector.elementAt(3) instanceof Player ) …
Dec 21, 2012 OOSSE - Java Lecture 7 36
37. Vector Methods
• Vector contains many methods including:
– capacity( )
– size ( )
– firstElement( )
– lastElement( )
– isEmpty
– removeAllElements( )
– removeElement( int index )
– indexOf ( Object element )
Dec 21, 2012 OOSSE - Java Lecture 7 37
38. A Vector version of Team
import java.util.*;
public class VecTeam {
private Vector <Player> thePlayers;
private int numPlayers;
private int maxPlayers;
private String teamName;
private Scanner kybd;
public VecTeam (String name, int num)
{
teamName = name;
maxPlayers = num;
numPlayers = 0;
thePlayers = new Vector <Player> (maxPlayers);
kybd = new Scanner (System.in) ;
}
Dec 21, 2012 OOSSE - Java Lecture 7 38
39. VecTeam
public boolean addPlayer( Player newPlayer )
{
// add another player to the team
if ( numPlayers == maxPlayers ) // the team is full
{
return false;
}
else
{
// add player to the team
thePlayers.addElement(newPlayer);
numPlayers++;
return true;
}
}
Dec 21, 2012 OOSSE - Java Lecture 7 39
40. VecTeam (continued)
public void outputTeamDetails()
{
System.out.println("Team name: " + teamName );
//output each player in turn
System.out.println("The players:");
for( int i=0; i < numPlayers; ++i)
{
System.out.println(thePlayers.elementAt(i));
}
}
Dec 21, 2012 OOSSE - Java Lecture 7 40
41. VecTeam (continued)
public void changePositions()
{ //output each player in turn and change position if required
for( int i=0; i < numPlayers; ++i)
{
System.out.println(thePlayers.elementAt(i));
System.out.println(“Change the player's position?");
String ans = kybd.next();
if (ans.equals("yes"))
{
System.out.print("Enter new position: ");
String pos = kybd.next();
Player p = thePlayers.elementAt(i);
p.setPosition(pos);
}
}
}
}
Dec 21, 2012 OOSSE - Java Lecture 7 41
42. Iterators
• A collection is a set of data
• Frequently it is useful to look at each item of data in the
collection in turn
• An iterator is an object that is used to iterate through the
data items of a collection
• Each collection provides an iterator of type Iterator
• The method hasNext( ) can be used to test if the collection
has any more data
• An iterator can be moved on to the next data item in the
collection using the method next( )
– Next returns the object referred to before the iterator moves
Dec 21, 2012 OOSSE - Java Lecture 7 42
43. Using Iterators in the VecTeam class
public void outputTeamDetailsITR()
{
System.out.println("Team name: " + teamName );
//output each player in turn
System.out.println("The players:");
Iterator itr = thePlayers.iterator();
while ( itr.hasNext() ) // while there are more players
{
Player nextPlayer = (Player)itr.next();
System.out.println(nextPlayer);
}
}
Dec 21, 2012 OOSSE - Java Lecture 7 43
44. Using Generic Types
• In the original versions of collections objects were stored
– That is any object of any type could be added to a collection
– The collections were type unsafe
• With the release of JDK1.5 the generic types mechanism
was introduced
• This allows the type of objects to be stored in a collection
to be specified
– The mechanism allows support for type checking at compile
time
• In the example using Vector earlier the generic type
mechanism was used to store Person objects
– Vetor <Person> thePlayers = new Vector <Person> (5);
Dec 21, 2012 OOSSE - Java Lecture 7 44
45. Java Generics versus C++ Templates
• Generics and C++ templates are not the same!
• Generics in Java provide compile time safety and avoid
the need for casts
– Improved encapsulation
– They use a technique known as type erasure
– The compiler keeps track of generics internally
– All instances use the same class file at compile/run time
• In C++ a template is more like a powerful macro
– Whenever a template class is instantiated with a new class
the entire code for the class is reproduced and recompiled
Dec 21, 2012 OOSSE - Java Lecture 7 45
46. The Java Collections Framework
• The Java Collections Framework provides unified support
for collections
• It contains:
– Interfaces
– Implementations
– Algorithms
• The core collection interfaces:
• Taken from: http://java.sun.com/docs/books/tutorial/collections/index.html
Dec 21, 2012 OOSSE - Java Lecture 7 46
47. Implementations
• General-purpose Implementations:
Interfaces Implementations
Resizable
Hash table Tree Linked list Hash table + Linked list
array
Set HashSet TreeSet LinkedHashSet
List ArrayList LinkedList
Queue
Map HashMap TreeMap LinkedHashMap
• Taken from: http://java.sun.com/docs/books/tutorial/collections/index.html
Dec 21, 2012 OOSSE - Java Lecture 7 47
48. Algorithms
• Algorithms provide re-useable code
• For example there algorithms to provide the following
functionality:
– Sorting
– Shuffling
– Searching
• The algorithms take the form of static methods in the
Collections class
– The first argument is the collection on which the algorithm is
to be carried out
– Many of the algorithms operate on instances of List
Dec 21, 2012 OOSSE - Java Lecture 7 48
49. Summary
In this lecture we have:
• Discussed the Has-A relationship
• Defined classes that contain instances of other classes
• Introduced concept of ownership of objects
• Reviewed the UML class diagrams used to indicate the
Has-A relationship
• Introduced Collections and the Java Collections API
• Discussed Generics
Dec 21, 2012 OOSSE - Java Lecture 7 49
Editor's Notes
Part of this lecture will be reserved for working through solutions to selected exercises from last week. Notes relating to this do not appear in the slides.