Download presentation
Presentation is loading. Please wait.
1
Introduction to Programming
2
To gain a sound knowledge of programming principles To gain a sound knowledge of object- orientation To be able to critically assess the quality of a (small) software system To be able to implement a (small) software system in Java Module Overview GOALS
3
Objects and classes Data types Constructors & methods Assignment - accessor & mutator methods Making choices: the conditional statement Object types & passing by reference Object interaction Repetition: using loops Collections: using array lists and arrays Module Overview TOPIC AREAS
4
Module Text Book BARNES & KOLLING Available from the university bookshop David J. Barnes & Michael Kölling Objects First with Java A Practical Introduction using BlueJ Fourth edition Pearson Education, 2008
5
Objects and Classes Week 1
6
Software development In order to design and build something complex, it is necessary to put some thought into how to break down the design into smaller chunks that are more easily dealt with. In software design, the most common methods are called Structured Design and Object- Oriented Design. Object-Oriented Design is the most recent type of development and the Java language is itself designed to support this type of design.
7
Object Oriented Design (OOD) Objects In OOD, a design is made up of a number of objects that may represent real-life objects and how they interact. These objects are comprised of two parts: attributes and methods. Attributes are data items that are associated with the object and methods are pieces of functionality. In other words attributes describe something about the object and methods are things that it can do, or have done to it. Classes In order to use an object we first define what that object is by means of a class description. A class description defines a type of object in terms of its attributes and methods. A class describes what all objects of a particular type have in common. Classes are the blueprints or templates for objects. Classes are used to create objects.
9
Specifying a class - Dog class what do dogs have in common? What attributes do dogs have? What behaviours do dogs have?
10
Dog class diagram Dog name colour size run sit bark bite eat attributes fields behaviours methods The Dog class is a template or blueprint for creating dog objects
11
Dog objects - instances of the class Dog class scooby snoopy mutley lassie From the Dog class we can create individual dog objects
12
Object State Each object has its own state. Its state is the values that the attributes are set to, which can be different from other objects of the same type State Methods Dog name scooby colour brown size big run() sit() bark() name snoopy colour white size small run() sit() bark() I am an object
13
Sending messages to objects - invoking methods We get objects to do things by calling their methods snoopy.run() calls the run() method on the object snoopy
14
Passing parameters to methods Sometimes when we call a method we need to pass some data to the method, to tell it exactly what to do. snoopy.run(10) scooby.bark(“loud”) scooby.sit(), snoopy.run() actual parameters
15
Object Orientation Advantages Reuse - Once we have defined a class we can use it over and over again to create many different objects of that type e.g. Dog class, BankAccount class Reuse - Once we have defined a class - someone else can use that class to create objects - so we can create class libraries Encapsulation - we can create objects from a class and use its behaviours without needing to know the internal details of how it works Reuse - when defining new classes we can compose classes from other existing classes to create complex objects
16
an object that is made up of other objects! Wheels, Seats, Chassis, Exhaust, Steering Wheel, etc, etc... Is this Aston Martin DB4 a Complex Object? And… a wheel itself is also a complex object! Tire, Trim, Hub Cap, etc, etc... WHAT IS A COMPLEX OBJECT? Object Model
17
CAR TIRE HUB CAP TRIM TIRE HUB CAP TRIM TIRE HUB CAP TRIM TIRE HUB CAP TRIM CHASSIS WHEEL SEAT REGISTRATION NUMBER Object Model
18
BlueJ Demonstration
19
Object – Represents an actual thing! Class – ‘Blueprint’ for making an object Method – Things an object can do (behaviour) Parameter – input required by an object method Data type – what type of data is allowed! Object Model Basics FUNDAMENTAL CONCEPTS
20
Many objects (instances) can be created from a single class. An object has attributes (fields), and those attributes have values assigned to them. the class defines what fields an object has, but each object stores its own set of values (state) Each class has source code (Java) associated with it that defines its fields and methods. Object Model Basics OTHER OBSERVATIONS
21
Object Model Basics STATE
22
Object Model Basics OBJECT INSTANCES
23
Required Reading Objects First With Java – A Practical Introduction using BlueJ Chapter 1 pp 1-9 (Objects and Classes)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.