Object- Oriented Design
Transcript: Attributes have private access, meaning being hidden from external objects. Only special public operations, known as accessors and mutators should allow external objects to access the values in attributes. Chapter 11 An Intro to Object- Oriented Design Chapter 11 *calling deposit(), and has passed these ^ parameters. This will deposit the amount and return newBalance. The statements above also assign default values to their attributes and methods. When a new object uses an existing method from its class it is written as followed- *Objects name followed by the method, seperated by a period. The chequeAccount is an object that has called the method displayBalance() Constructors are prewritten methods that have the same name as their class, once they are called, the constructor will create an object, and assign initial values. In some cases, the method may also return a value to the caller, a message to a chequeAccount object requesting deposit services can be called as followed: chequeAccount.displayBalance() Objectives Objects, Classes, Attributes, Methods, Inheritance. Class Diagrams End 3. Develop a test or driver algorithm to test the solution. Instantiating objects *Inside parenthesis can be attributes sedan.accelerate() hatchback.accelerate() In Object- Oriented Design the program requires classes, attributes, and methods to be represented in a class Diagram, which is similar to a defining diagram. Accessors, Mutators, Messages Keyword 'new' refers to a new object, once instantiated as a new class, it will inherit the same attributes as the class, it will always be upper case. 1. Identify the objects and their attributes, responsibilities and operations. Private access means that the attributes and methods are invisible to the rest of the system. Public access is visible to the rest of the system. All attributes should be private! Private(-), Public(+). Attributes(characteristics) on the top, methods(actions) on the bottom. It does not describe how or when the operations are to be performed. 11.1 Introduction to object-oriented design. A mutator enables external values to be passed to attributes. They start with the word 'set', in other words, it sets the value of an attribute. Public and Private access methods DisplayBalance(), deposit(), and withdraw() are all visible to the user, calculateinterest() and verifySufficientFunds() are needed for the public methods to be operated. These private methods are only visible in the BankAccount class, not externally visible. Accessor operations pass attributes to external objects, but do not change the values. They start with the word 'get', in other words it gets the value of an attribute. A message is a call made by one object to an operation in another object, it can be written as followed: There are 3 steps in creating an object-oriented solution for a problem with just one class: An object in this design can be compared to a milk jug, where it can perform, such as filling and pouring, the jug has a handle which can be considered a user-friendly interface. In object-oriented program, the jug is known as an object and the operations it does is called methods. A class is used to describe a group of objects that share some common properties. For example a milk jug, juice jug, and water jug share common properties, in other words are a class. The process of creating objects from classes is called instantiation, many objects can be instantiated from a class. Attributes are the set of properties or characteristics that describe a particular object. Methods are a set of operations which are performed on an object. Inheritance allows a new object to inherit the same attributes and methods as an existing object. Object- Oriented Design To Introduce object-oriented design. To define objects, classes, attributes, operations, and information hiding. To introduce public and private operations, accessors, and mutators. To list the steps required to create an object-oriented solution to a problem. Objects must be created in object-oriented programs, every time an object is instantiated from a class, a special operation or set of instructions, known as a 'constructor' method is called or invoked. 2. Design the algorithms for the operations or methods, using structured design. Creating an object-oriented solution Example- Create sedan as new Car() Object-oriented programming uses the same concepts as procedural programming, however focuses on the objects that make up the program rather than the processes. An object-oriented design asks that you interact with the problem in much the same way that your interact with the world, treating the problem as a set of separate objects that relate to each other. An object-oriented program is a set of interacting objects, each one responsible for its own activities and data. chequeAccount.deposit(amount, newBalance) Format of Instantiation- Create object-name as new Class-name()