1 / 77

OOP Class 2

OOP Class 2. An Object of c lass Time. OPERATIONS DATA. Set. Private data: hrs 8 mins 25 secs 42. Increment. Write. Time. Definitions. Definitions. Definitions of object on the Web:

ashlyn
Télécharger la présentation

OOP Class 2

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. OOPClass 2

  2. An Object of class Time OPERATIONSDATA Set Private data: hrs 8 mins 25 secs 42 Increment Write . . . Time

  3. Definitions

  4. Definitions • Definitions of object on the Web: • a tangible and visible entity; an entity that can cast a shadow; "it was full of rackets, balls and other objects" • Definitions of object-oriented on the Web • “object-oriented ... techniques where data carries with itself the "methods" (also known as "functions") used to handle that data. An OO programmer, for instance, can write a statement such as "object.print()" without having to be concerned about what kind of object will be involved at "run time" or what its printing method is. Object-oriented code is both more flexible and more organized, so it is far easier to write, read, and change than procedural code…” www.3dartist.com/WP/dempy/help/glossary.htm • “… A style of software development and packaging based on how real world objects relate to one another. Data and procedures are combined in objects; objects communicate with each other via messages; similar objects are grouped together into classes; data and procedures are inherited through a class hierarchy…”www.olenick.com/html/glossary.html

  5. Definitions • Definitions of object-oriented design on the Web: • entails transforming the analysis model into a feasible design. kaykeys.net/science/computerwork/oodesign/ • A software design method that models the characteristics of abstract or real objects using classes and objects. software.allindiansite.com/java/ojava.html • Object-oriented design (OOD) is a design method in which a system is modeled as a collection of cooperating objects and individual objects are treated as instances of a class within a class hierarchy. • en.wikipedia.org/wiki/Object-oriented_design

  6. Definitions of object-oriented analysis on the Web: • Object-oriented analysis • builds a model of a system that is composed of objects. The behavior of the system is achieved through collaboration between these objects, and the state of the system is the combined state of all the objects in it. Collaboration between objects involves them sending messages to each other. • Definitions of object-oriented programming on the Web: • “… A programming approach based on the concepts of data abstraction and inheritance. Unlike procedural programming techniques, …” • “… Style of programming characterized by the use of separate "objects" to perform different tasks within a program. These "objects" usually consist of an abstract data type or class, along with the methods used to manipulate that abstract data type …” • “… A programming methodology built around objects and based on sending messages back and forth between those objects. The basic concepts of object-oriented programming are encapsulation, inheritance, and polymorphism …”

  7. Modeling the Real World • Components of a software system is an interpretation of the real world • Model , a representation of parts of the real world • Algorithm, capture the computation needed to manipulate the model • Object Orientation is a software development model that makes use of objects as a representation of the real world • An object represents anything in the real world that can be distinctly identified. • A class represents a set of objects with similar characteristics and behavior

  8. History

  9. Find Weighted Average Print Weighted Average Module Structure Chart Main Get Data Prepare File for Reading Print Data Print Heading

  10. . . . . . . . . . OBJECT OBJECT FUNCTION FUNCTION FUNCTION Two Design Strategies FUNCTIONALOBJECT-ORIENTED DECOMPOSITION DESIGN OBJECT

  11. Software Process Models

  12. Unified Process • a “use-case driven, architecture-centric, iterative and incremental” software process closely aligned with the Unified Modeling Language (UML) • Tools are used to describe customer views (use cases) • Used mainly for OO based methodologies • Runs in phases

  13. The Unified Process (UP) inception Phase 1 Communication + Planning Phase 2 Planning + Modeling elaboration inception Phase 3 Coding, unit test & integrate Components result Phase 4 Deployment

  14. UP Phases

  15. UP Work Products

  16. Agile Development

  17. The Manifesto for Agile Software Development • “We are uncovering better ways of developing software by doing it and helping others do it. Through this work we have come to value: • Individuals and interactions over processes and tools • Working software over comprehensive documentation • Customer collaboration over contract negotiation • Responding to change over following a plan • That is, while there is value in the items on the right, we value the items on the left more.” Kent Beck et al

  18. What is “Agility”? • Effective (rapid and adaptive) response to change • Effective communication among all stakeholders • Drawing the customer onto the team • Organizing a team so that it is in control of the work performed Yielding … • Rapid, incremental delivery of software

  19. An Agile Process • Is driven by customer descriptions of what is required (scenarios) • Recognizes that plans are short-lived • Develops software iteratively with a heavy emphasis on construction activities • Delivers multiple ‘software increments’ • Adapts as changes occur

  20. Extreme Programming (XP) • The most widely used agile process, originally proposed by Kent Beck • XP Planning • Begins with the creation of “user stories” • Agile team assesses each story and assigns a cost • Stories are grouped to for a deliverable increment • A commitment is made on delivery date • After the first increment “project velocity” is used to help define subsequent delivery dates for other increments

  21. Extreme Programming (XP) • XP Design • Follows the KIS principle • Encourage the use of CRC cards (see Chapter 8) • For difficult design problems, suggests the creation of “spike solutions”—a design prototype • Encourages “refactoring”—an iterative refinement of the internal program design • XP Coding • Recommends the construction of a unit test for a store before coding commences • Encourages “pair programming” • XP Testing • All unit tests are executed daily • “Acceptance tests” are defined by the customer and executed to assess customer visible functionality

  22. Extreme Programming (XP)

  23. OO Design & Programming Java Basics

  24. Classes and Objects Class Point { Int x, y; Public void move (intd dx, int dy) { x +=dx; y +=dy; } } • An object: point1 • Attributes or fields: int x, y; • A method: void move(int dx, int dy) • A message: point1.move(10, 10)

  25. An Object of class Time OPERATIONSDATA Modularity Abstraction Encapsulation Inheritance Polymorphism Message Passing Set Private data: hrs 8 mins 25 secs 42 Increment Write . . . Time

  26. Developing a Java Application • Write the source code • Using an Integrated Development Environment (IDE) or text editor • Save in a .java file • Compile the source code: javac ClassName.java • Creates .class file • Execute the application: java ClassName • Run by the Java Virtual Machine (JVM)

  27. A First Application 1 // First program in Java 2 // FirstProgram.java 3 4 public class FirstProgram 5 { 6 public static void main( String [] args ) 7 { 8 System.out.println( "Programming is not " 9 + " a spectator sport!" ); 10 System.exit( 0 ); 11 } 12 }

  28. Class: FirstProgram • Method: main(...) • Statement: System.out.println(...) • Comments: • // a comment • /* another comment */ • Source file: FirstProgram.java

  29. Program Errors • Compiler errors • Found by the compiler. • Usually caused by incorrect syntax or spelling • Run-time errors • Reported by the JVM • Usually caused by incorrect use of prewritten classes or invalid data • Logic errors • Found by testing the program • Incorrect program design or incorrect execution of the design

  30. Program Life Cycle

  31. Introduction: Java Platform • JavaTM platform is based on the idea that the same software should run on many different kinds of computers, consumer gadgets, and other devices. • Portability • Java platform allows you to run the same Java application on lots of different kinds of computers.

  32. JVM • Java virtual machine or "JVMTM” • a translator that turns general Java platform instructions into tailored commands that make the devices do their work

  33. Java Program Phases • Edit • IDE, vi, emacs, notepad • Compile • javac • Load • Class Loader • Verify • Verifier (Security and Validation) • Execute • Java Interpreter (java or appletviewer)

  34. The java Compiler • javac • Creates bytecodes • Stored on disk as .class • Each file contains bytecode for one and only one class

  35. The java Class Loader • Loads bytecodes in memory • Loads .class files from disk into memory

  36. The java Bytecode Verifier • Confirms that all bytecodes are: • Valid and • Don't violate Java’s Security restrictions • Works on bytecodes from memory

  37. The java Interpreter • Reads bytecodes and translate them into a language that is relevant to the targeted computer architecture • PC • Machintosh • Cell Phone • For applets execution its built into the browser or the appletviewer

  38. Your first program: HelloWorldApp.java • Displays the greeting "Hello world!". To create this program, you will:  • Create a source file • A source file contains text, written in Java. • Compile the source file into a bytecode file. • The compiler, javac, converts these instructions into a bytecode file

  39. Your first program: HelloWorldApp • Run the program contained in the bytecode file • The Java interpreter implements the Java VM • This interpreter takes your bytecode file and carries out the instructions by translating them into instructions that your computer can understand.

  40. JRE

  41. JAVA Program public class HelloWorldApp { public static void main(String[] args) { System.out.println("Hello World"); } }

  42. Steps • Save the file as HellowWordApp.java • Compile • Javac HellowWordApp.java HellowWordApp.class • Run the program • Java HellowWordApp

  43. Output

  44. What Can be a Class? • Physical Objects – equipments, devices, products • People – Students, Faculty, Customers • Organizations – Universities, Companies, Departments, Bank • Places – Buildings, Rooms, Seats • Events – Mouse click, order request, purchase orders • Concepts – Transaction • The domain determines the classes

  45. What Features Should a Class Have? • Actions should be modeled as methods of a class • Verb phrases • Underline the verbs and nouns in the description of the requirements and use cases • Nouns are candidate classes or attributes • Verbs are candidate methods

  46. Java Programming Language Java Basics OO Basics UML Basics

  47. Data Types, Variables, and Constants • We use Symbolic Names to refer to data • We must assign a data type for very identifier (symbolic name) • Declaring Variables • Primitive Data Types • Initial Values and Literals • String Literals and Escape Sequences • Constants

  48. Data Types • For all data, assign a name (identifier) and a data type • Data type tells compiler: • How much memory to allocate • Format in which to store data • Types of operations you will perform on data • Compiler monitors use of data • Java is a "strongly typed" language • Java "primitive data types" byte, short, int, long, float, double, char, boolean

  49. Declaring Variables • Every Variable must be given a name and a data type • Variables hold one value at a time, but that value can change • Syntax: dataType identifier; or dataType identifier1, identifier2, …; • Naming convention for variable names: • first letter is lowercase • embedded words begin with uppercase letter

  50. primitive integral boolean floating point byte char short int long float double Java Primitive Data Types • byte, short, int, long , float, double, char, boolean

More Related