1 / 23

OBJECT ORIENTED CONCEPTS

OBJECT ORIENTED CONCEPTS. Chapter 2. Introduction. In the real world, there are many individual objects all of the same kind . There may be thousands of cars, all of the same make and model. Each car was built from the same set of blueprints and therefore contains the same components .

afi
Download Presentation

OBJECT ORIENTED CONCEPTS

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. OBJECT ORIENTED CONCEPTS Chapter 2

  2. Introduction • In the real world, there are many individual objects all of the same kind. There may be thousands of cars, all of the same make and model. Each car was built from the same set of blueprints and therefore contains the same components. • In object-oriented terms, we say that your car is an instance of the class of objects known as cars. • Many objects can be instantiated from a single class. • Therefore a class is an abstract descriptor for a set of instances.

  3. Class • A class is the blueprint from which individual objects are created • These objects have similar characteristics (common structure, common behaviour, common relationship and common semantics). • Semantics is a set of rules that specify the meaning of syntactically legal construct in a programming language. • Classes are sometimes referred to as entity classes or model class

  4. Class • For example, • a Car class may be used to represent the common state (e.g., make, model, colour, mileage, etc...) and behaviour (e.g., start, stop, changeGear, turn etc...) between all car objects • a 2DShape class may represent common state (e.g., centerPoint, lineWidth) and behaviour (e.g., calculateArea, calculatePerimeter)  for 2D shapes.

  5. Class CLASS : Car Another Example ATTRIBUTES Make Model Number of doors Engine size Colour METHODS Stop Turn Accelerate brake

  6. TASK 1 • List out the classes that you think are involve in the Student Information System?

  7. CLASS • Class table/notation is used to model the static structure of a system which is based on data • it contains the name of class, attributes and methods

  8. Class Class name A class Car represented in class notation. attributes methods

  9. The following codes implements a class car (it is just a blueprint that might be used in an application) : class car { String make = “ “; String model = “ “; int doors=0; intbodyLength = 0; intengineSize = 0; String colour = “ “; int speed = 0; void accelerate(int increment) { speed = speed + increment; } void brake(int decrement) { speed = speed - decrement; } } Implementation in Java

  10. Implementation in Java The following carDemo class will creates 2 car objects and invoke their methods: class carDemo { public static void main(String[] args) { // Create two different car objects car car1 = new car(); car car2 = new car(); // Invoke methods on those objects car1.accelerate(50); car2.brake(20) ; }

  11. Objects • Software objects are conceptually similar to real-world objects • They too consist of state and related behavior. • An object stores its state in fields (variables in some programming languages) and exposes its behavior through methods (functions in some programming languages) attributes – they know things behavior (methods) - they do things

  12. Objects • object of the same type will have an identical set of attributes • Attributes of one object may contain different data values from those of another object.

  13. Objects • Object can be considered as a container for a set of data and the operation that need to be performed on it. • Properties are : • It has a unique identity for the lifetime of the object • Its data is in the form of a set of attributes, each has a value at any given point in time. • A set of methods can be performed on the data • It is an instance of a class

  14. Objects Example - CLASS: car An instance (object) of the class car refers to a specific vehicle eg. Mercedes, Honda, BMW, Toyota

  15. ATTRIBUTES • Attributes are data items that define a class • They are features/properties that help describes the system

  16. TASK 2 • List the attributes necessary for the class student

  17. CLASS & OBJECTS A Car class Car objects Object Notation/diagram Class Notation

  18. CLASS & OBJECTS • There are 4 different types of methods/behaviour: • Constructor methods – executed each time an instance of the class is created. Often used to initialise attributes. • Mutator methods – methods which allow other objects to set or change the value(s) of an object attribute(s). This method begins with the word set e.g. setName. • Accessor methods – methods which allow other objects to query the value(s) of a n object attribute(s). This method begins with the word get e.g.getName. • Other methods – normally used to perform more complex operations e.g. calculation, validation

  19. CLASS & OBJECTS • Tips : • To find class/objects/attributes, read the problem definition for nouns and noun phrases. (Not all nouns in the problem statement are vital to the solution) • To identify methods, look at the verbs that describe the actions performed by the nouns

  20. CLASS & OBJECTS • Example: • A program is required to process the employee pay. The employee data is read from a file. For each employee, compute the employee’s monthly pay and then print a report containing their detail together with their pay. The input file contains the employee number, pay rate, the number of hours worked and the overtime hours worked in a week. Assuming the overtime rate rate is 1.5 times the standard rate. • Analyzed the above problem.

  21. CLASS & OBJECTS Listing the attributes

  22. CLASS & OBJECTS • Example: • A program is required to process the employee pay. The employee data is read from a file. For each employee, compute the employee’s monthly pay and then print a report containing their detail together with their pay. The input file contains the employee number, pay rate, the number of hours worked and the overtime hours worked in a week. Assuming the overtime rate rate is 1.5 times the standard rate. • Analyzed the above problem.

  23. CLASS & OBJECTS Listing the methods

More Related