Download presentation
Presentation is loading. Please wait.
1
Objects as a programming concept
IB Computer Science
2
HL Topics 1-7, D1-4 1: System design 2: Computer Organisation
3: Networks 4: Computational thinking 5: Abstract data structures 6: Resource management 7: Control D: OOP
3
HL & SL D.1 Overview 1: System design 2: Computer Organisation
3: Networks D.1 Objects as a programming concept D.1.1 Outline the general nature of an object D.1.2 Distinguish between an object (definition, template or class) and instantiation D.1.3 Construct unified modelling language (UML) diagrams to represent object designs D.1.4 Interpret UML diagrams D.1.5 Describe the process of decomposition into several related objects D.1.6 Describe the relationships between objects for a given problem D.1.7 Outline the need to reduce dependencies between objects in a given problem D.1.8 Construct related objects for a given problem D.1.9 Explain the need for different data types to represent data items D.1.10 Describe how data items can be passed to and from actions as parameters 4: Computational thinking 5: Abstract data structures 6: Resource management 7: Control D: OOP
4
Topic D.1.1 Outline the general nature of an object
5
Definition: object An object is a ‘thing’.
An object is an abstract entity. It has two components: data and actions.
7
Object & Class Object - Objects have states (variables) and behaviors (methods). Example: A dog has states - color, name, breed as well as behaviors -wagging, barking, eating. An object is an instance of a class. Class - A class can be defined as a template/blue print that describes the behaviors/states that object of its type support.
8
etc. All these objects have a state and behavior.
Real world vs Software What are real-world objects? Cars, Dogs, Humans, etc. All these objects have a state and behavior. If we consider a dog, then its state is - name, breed, color, and the behavior is - barking, wagging, running Software objects also have a state and behavior. A software object's state is stored in fields and behavior is shown via methods.
9
Example: Fields States Methods Behaviours
10
Constructors Every class has a constructor.
Each time a new object is created, at least one constructor will be invoked (called/run). The main rule of constructors is that they should have the same name as the class. A class can have more than one constructor.
11
Steps in object creation:
A class provides the blueprints for objects. An object is created from a class. In Java, the new key word is used to create new objects. There are three steps when creating an object from a class: Declaration: A variable declaration with a variable name with an object type. Instantiation: The 'new' key word is used to create the object. Initialization: The 'new' keyword is followed by a call to a constructor. This call initializes the new object.
12
Example: Output:
13
Summary of code
14
Output:
15
We tend to split classes
Many methods Object Class main() Running Class
16
Output:
17
Summary – key terms Think Pair Share Object Class State Behaviour
Field Method Constructor Declaration Instantiation Initialization Think Pair Share
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.