Presentation is loading. Please wait.

Presentation is loading. Please wait.

Programming. To gain a sound knowledge of programming principles To gain a sound knowledge of object- orientation To be able to critically assess the.

Similar presentations


Presentation on theme: "Programming. To gain a sound knowledge of programming principles To gain a sound knowledge of object- orientation To be able to critically assess the."— Presentation transcript:

1 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 Module Text Book BARNES & KOLLING David J. Barnes & Michael Kölling Objects First with Java A Practical Introduction using BlueJ Fifth edition Pearson Education, 2012 ISBN 0-13-283554-1

4 Introduction to Objects and Classes Week 1

5 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.

6 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.

7

8 Specifying a class - Dog class what do dogs have in common? What attributes do dogs have? What behaviours do dogs have?

9 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

10 Dog objects - instances of the class Dog class scooby snoopy mutley lassie From the Dog class we can create individual dog objects

11 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

12 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

13 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

14 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

15 BlueJ Demonstration

16 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

17 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

18 Object Model Basics STATE

19 Object Model Basics OBJECT INSTANCES

20 Required Reading Objects First With Java – A Practical Introduction using BlueJ Chapter 1 pp 3-11 (Objects and Classes)


Download ppt "Programming. To gain a sound knowledge of programming principles To gain a sound knowledge of object- orientation To be able to critically assess the."

Similar presentations


Ads by Google