IT-IPT 01 PDF Object-Oriented Application Development

Summary

This document provides an introduction to object-oriented application development, focusing on fundamental concepts like objects, classes, attributes, and behaviors. It also touches upon structured application development and UML diagrams.

Full Transcript

IT-IPT 01 CHAPTER 7 – Object-Oriented Application Development Part 1 Overview of Object-Oriented Application Development  In the real world, we are surrounded by different interacting things such as people, trees, cars, buildings, and so on. This real-world things are often considered parts...

IT-IPT 01 CHAPTER 7 – Object-Oriented Application Development Part 1 Overview of Object-Oriented Application Development  In the real world, we are surrounded by different interacting things such as people, trees, cars, buildings, and so on. This real-world things are often considered parts of the real-world systems in which the things within the system are related and can interact in an organize way. A real-world system is often managed using an information system. For example, a business enterprise or a university are complex systems that requires sophisticated information system. The things that are components of such systems (managers, supervisor, accountant, inventories, sales, products, teachers, courses, and students) are often modeled or represented within the information system to keep the real-world system organized and running smoothly.  You can divide the real-world things such as students, teachers and courses into groups or categories, called classes. If you are reading and studying this chapter you might and probably belong to the student group or class. Your professor/instructor belongs to teacher class and this IPT01 belongs to a course class. If you use the term object instead of thing, then you could say that a real-world object (a thing in the real-world object that has attributes and behaviors) can belong to a particular real-world class (a category to which real-world object belongs). The representation of the real-world object which belongs to a real-life class in necessary as with use of software object (depiction of a real-world object in computer memory) that goes to a software class (program code that depicts a real-world class) that you write using a programming language such as Java. Attributes and Behaviors of Objects  What exactly is an object? It is simply an entity with two primary features. First a real-world object has attributes. Object attributes are the characteristics or features that define the object. For example a real-world student objects in a university information system have many attributes, including the name, address, favorite color, and favorite food. Though, if your task is to develop a UIS(University Information System), the attributes you must consider are the name and address, and not the favorite color and favorite food. A student object in a UIS could have other attributes which includes student ID number, a gender, contact number, address and birthdate.  A real-world student object would have another important attribute such as a class schedule, which by itself can also be considered as an object. A schedule object has attributes, such as semesters and courses. The course can also be assumed as an object in this example. A course has attributes such as course number, course title, and section. A course section is an object that has attributes such as number, meeting time, room number, and instructor. An instructor is an object that has attributes such as a faculty ID Attributes and Behaviors of Objects (cont..)  You can see that analyzing and designing an information system using all these objects can get very involved. The fact that all these objects (student, schedule, course, section, and instructor) contains attributes/feature/characteristics and can be related to each other. Modelling this complex real-world system (UIS) involves real-world objects like students, course and instructors can be done using an OOP language such as Java.  The second major feature of a real-world objects is object behavior. The object’s behavior are methods, actions, operations or processes that describe what the object can do. As with attributes, there are some action/methods relevant to a particular information system. The action like eating, sleeping and studying can be an example of an object’s behavior, but those are not applicable to a university information system. The behaviors that are relevant in the university information system can include student behavior of registering for a particular course, paying tuition fee, taking exam, attending class, submitting requirements and checking grades. You are undoubtedly aware that a complex university system needs an information system to keep track of all students, course and instructors, including their relevant attributes and behavior Structured Application Development  As you know, information systems are needed and manage real-world systems such as a university or a business enterprise. An information system is often composed of many interacting applications, such as a student-scheduling application, a grade-assignment application, and learning management system. Applications can be developed in essentially one of two ways, either using structured application development or object-oriented application development. These two approaches have much in common- regardless of the approach, the developer must perform these steps: 1. Understand the problem. 2. Designing or planning the application. 3. Write the code. 4. Compile and test. 5. Deploy the application. The Object-Oriented Application Development (OOAD) in Action  The object-oriented application development primary focus is on framework or context of object, which involves the combination of data (attributes) and behavior (process). The object-oriented application development (OOAD) is an approach in creating applications or programs that stresses and highlights on objects within the system and how this objects interrelate or interact. The OO developer must still go through the steps of understanding the problem, planning the application, writing the code, compiling and testing and deploying the application, thinking in terms of object. For example, a student scheduling application involves student object, course objects and schedule objects. Object and Classes  The objects and classes are the most important element or concept in an example, application development. The following section will discuss and explain these concepts.  OBJECTS  As discussed previously, a real-world object such as a person, a car, a tree, an invoice, course is something that has attributes/states and behaviors/methods. For example, an object student can be stored in computer memory to model a certain real-world student. The term instance variable is used to describe an attribute of an object, and the term instance method is used to describe the behavior of the object (instance methods are usually called as method). A student object can have instance variable of name, gender, address, course and grade with the corresponding methods for course and grade the setCourse(), getGrade().  An object can be recognized by giving reference or name. For example, a student object can be created as shown in the following Java statement: Student myStudent = new Student (sid, lastName, firstName, gender); Objects (cont..)  The reference to the student object is myStudent (you can use any reference you choose, such as theStudent, aStudent, studentA, or student1 ), which refers to the object in the memory. The variable myStudent is actually a reference variable that holds a memory address of the object. The data type for this object is Student. This is an example of an abstract data type, which is an entire set of instance variable (sid, lastName, firstName, gender) and methods for manipulating those variables.  The java keyword new is use to create an object. The code Student (sid, lastName, firstName, gender) is a call to the constructor named Student, a class method that brings out the specifics or the details in creating a Student object. Classes  Representing real world objects with software objects is a great idea, but how are the objects blueprint? This is accomplished with the aid of a java class. You have already created a dozen of class using java. The class can be used and considered as the blue print or template for creating objects in OO applications. Such class is called an object-defined class. An object- defining class is said to have members –data members (instance variable or field) and method members (usually designed to manipulate the member fields). Instantiate is the technical term used to signify the method or procedure of making and creating an object from a specific class. The Visibility of Instance Variables and Methods  Variables that have been declared within a method have method scope. This means that a variable can only be referred or access by their simple names inside that method (the local scope). In object-defining class, the instance variables is declared within a class, not within a method, and basically define what object is. Such variables have a characteristic known as visibility which is similar to scope. The visibility means that the instance variable can also be referenced or access by its simple name. The access modifier describe and define the visibility of the instance variable. The access modifiers can be private, public or protected. In the private access modifier variables has only visibility within its defining class, public access modifier means it has visibility in any class, protected access modifier implies that the instance variable has visibility only in subclasses of that class, or classes in the same package. The Visibility of Instance Variables and Methods UML Diagram A UML diagram is a way to visualize systems and software using Unified Modeling Language (UML). Software engineers create UML diagrams to understand the designs, code architecture, and proposed implementation of complex software systems. UML diagrams are also used to model workflows and business processes. Coding can be a complicated process with many interrelated elements. There are often thousands of lines of programming language that can be difficult to understand at first glance. A UML diagram simplifies this information into a visual reference that’s easier to digest. It uses a standardized method for writing a system model and capturing conceptual ideas. UML Diagram (cont…) There are two subcategories of UML diagrams:  Structural diagrams visualize the components that make up a system and the relationship between them — showing the static aspects of a system.  Behavioral diagrams represent what happens within a system — including how the components interact with each other and with other systems or users. The Class Diagram  The class diagram is component of a Unified Modeling Language (UML) which defines the static or fixed view of a class or application. Class diagram often use in describing, documenting, and visualizing diverse components of an application. It defines both the attributes and behaviors of a specific class. It also captures the constraints and relationship between classes on the system. The use of class diagram is highly suggested in the modeling of object-oriented systems. Because this is the only UML diagrams that can be mapped directly with object-oriented languages like java. The Class Diagram (cont..) Upper portion: The class name (Student). This portion contain the name of the class and is required for reference. Middle portion: The attributes of the class, (studentId, name, course, yearLevel and their corresponding data types), is the portion where the attribute/qualities/characteristics of the class is defined. Bottom portion: The class operations or methods, is the portion where each operations and methods are listed. The methods defines the interactions with data in the class. The bottom portion in this class diagram can contain methods which can be a mutator method (setter method) and accessor method (getter method). The term mutator means to change or alter and the accessor means to access or retrieve. These sets of methods are used to assign and get values from the instance variables. Member access modifiers or visibility.  There are different symbols use to denote the access modifier or visibility of attribute or method in a class. The access modifiers can use plus sign (+) for public, minus (-) for private, hashtag (#) for protected, tilde (~) for package, slash (/) for derived, and undeline (_) for static attributes and methods. In visibility, the public and private are the most commonly used access modifiers. Example How to find the required classes in the system? APPLICATION  Understanding the Problem To begin a simple OO application understanding the domain problem should come first. The domain of the project would be a selling of clothes. In this application the sale is accomplished by providing an invoice that contains invoice number, date of sale, and the total amount for the sale. The application allows the salesperson to enter an invoice number and total. The invoice date comes from the system clock of the computer. Because the manager offers 5 percent discount to the store’s best customers. There are two types of invoices the one with no discount and the other with 5 percent discount.  Planning the Application In creating a plan for this application, the UML class diagram will be used. This diagram will serve as the blueprint of the application APPLICATION (cont..) The name of the class is Invoice that is displayed on the top section. The data member are listed in the middle section. The invoice has five instance variables: invoiceNumber, invoiceDate, invoiceType, invoiceTotal and discountPercent. All instance variables in the invoice are set to private by putting (-) sign in the begging of each variables. These variables are accessed and manipulated using the public mutator methods and the accessor methods. The (+) sign is placed in the beginning of each method to denote that the methods are public. APPLICATION (cont..) APPLICATION (cont..)  Compiling and Testing The file Invoice.java can be compiled but cannot be tested unless an application class (with a main method) is added in the class. Encapsulation  They can be defined as the process of wrapping, bundling or binding the data and methods that manipulate data together. This OOP concept preserves the implementation away from its user thus keeping it safe from outside, intrusion, and misuse. This concept headed towards another important concept of OOP which is the data hiding and data abstraction.  Data abstraction is a process in which only the interface are expose to the users thus hiding its implementations and details away from the user. Application Classes  The class with main method is required in an application class because this method is the starting point of execution. The object-defining class simply contains attributes and behavior, and another class is required in order to check whether the object-defining class is working properly. This class is called an application class or a driver class. The Invoice class is used to define invoice objects, but a program called InvoiceApp.java that contains the main method is needed to drive the entire application, making it useful for processing invoices. This application class follows the input-process- output pattern of most procedural applications. That is because application class is indeed very procedural Object Interface  In an OO application the object interface can be described as a set of methods in a class, use to operate the object (instance variables). Each method in a class has a method signature, which refers to everything a programmer needs to know about how to use the method (the name, visibility, return type, and parameters). For example, part of the interface of an Invoice object could be its constructor. The construct’s signature looks like this: The Composition Relationship between Classes  Composition is a typical component of an object-defining class which specifies the class is made of other objects. The composition is used when one instance variable is reference to an object. Figure 4.9 illustrates example of composition relationship between the InvoiceWithProduct class and the Product class using UML class diagram The Composition Relationship between Classes (cont..)  This kind of relationship is also called has-a relationship which implies that one class “has a/an” object from another class. Example Person has-a Leg, Person has-a Hand

Use Quizgecko on...
Browser
Browser