- Advanced Object - Oriented Concepts
-
Methods
- Represent behaviors, are used to perform operations or other actions.
- When is defined as public, other objects access it.
-
Modeling Tools
- Provide mechanism to create and manipulate class diagrams.
-
UML class Diagrams
- Is defined by three separate sections:
~ The name itself
~The data (attributes)
~Behaviors (methods)
-
Messages
- Are the communication mechanism between objects.
-
Program
- A collection of objects.
-
Classes
- Characteristics of objects.
- Are pieces of code.
- The data of a class is represented by attributes,
- Concepts
-
OOP
- The attributes and behaviors are contained within a single object
-
Procedural
- The attributes and behaviors are normally separated.
- Design
- Difference
- Procedural vs OOP
-
Object
- Is an entity that contains both data and behaviors.
- Are the building blocks of an OO program.
-
Attibutes
- The state of the object.
- Be declared as private.
- Are never part of the interface.
-
Behaviors
- Are contained in methods.
- Represents what the object can do.
-
Getters and Setters
- Controlled access to an object's data.
- Introduction to Object - Oriented Concepts
-
Encapsulation
- Is defined by the fact that objects contain both the attributes and behaviors.
- Fundamental Concepts
-
Composition
- It is natural to think of objects as conaining other objects.
- Objects are often built, or composed, from other objects.
-
Polymorphism
- It is often cited separately as one of the most powerful advantages to OO technologies.
-
Constructor
- As the entry point for the class.
-
Perform initializations and start-up tasks.
- STACK. is a data structure that is a last-in, first-out system.
-
Inheritance
- Allows a class to inherit the attributes and methods of another class.
- Code reuse.
-
Subclass
- Child class or derived class, is an extension of the superclass.
-
Superclass
- Parent class or base class, contains all the attributes and behaviors that are common to classes that inherit from it.
- How to Think in Terms of objects
- Providing the Absolute minimal user interface possible
-
Rules
- Give the users only what they absolutely need.
- Public interfaces define what the users can access.
- To design classes from a user's perspective and not from an information system viewpoint.
- Designing a class that you go over the requirements an the design with people who will actually use it.
-
Abstract thinking when designing interfaces
- A highly abstract interface is more useful than a highly concrete interface.
- It is possible to write a very useful, concrete class that is not at all reusable.
- Difference between the Interface and Implementation
-
Implementation
- Details are hidden from the user.
-
Interface
- Are only the services the end user needs are presented.
- Show?
-
Identifying the Implementation
- The class is designed and all the methods required to perate the class properly are in place,.
- Contains the code that represents that state of an object.
-
Determining the Users
- who are the users?
- Consider that users. so the interface is realistic and reality usable.
-
Object Behavior
- Begin identifying the purpose of each object and what it must do to perform properly.
-
Environmental Constraints
- Imposes limitations on what an object can do.
-
Identifying the Public Interfaces
- With all the information gathered about the users, the object behaviors, and the environments you need to determine the public interfaces for each user object.
-
Constructors
- Are methods that share the same name as the class.
- The object is initialized in the constructor.
-
When is a constructor called?
- When a new object is created, one of the first things that happens is that the constructor is called.
-
Initializing Attributes
- The initialization is often used for initialization purposes. Is a common function performed within a constructors.
-
The default Constructor
- One constructor always exists,
- If you do not provide a constructor, the system will provide a default constructor for you.
-
What's inside a constructor?
- Code included inside a constructor should set the newly created object to its initial, stable, safe state.
- For example: A count.
-
Providing a Constructor
- The default constructor provided by the compiler, for documentation and maintenance purposes.
-
Using Multiple Constructors
- An object can be constructed in more than one way, so, you need to provide more than one constructos.
- When in the parameters declared the methods is called Overloading Methods.
- Overloading Methods
- Signatures
- Using UML to Model Classes
- No return type
- How Superclass is Constructed
-
Operator Overloading
- You to change the meaning of an operator.
-
Multiple Inheritance
- Allows a class to inherit from more than one class.
- Can significantly increase the complexity of a system.
- Can even solve some problems quite elegantly.
-
Ignoring the Problem
- Simply ignoring a potential problem is a recipe for disaster.
-
Throwing an Exception
- The exceptions are unexpected events that occur within a system.
- This solves the problem of trying to figure out where the problem started and unwinding the code to the proper point.
-
The design of Constructors
- It is good practice to identify a stable state for all attributes and then initialize them to this stable state in the constructor
- Initializing to zero is not always the best policy.
- Error Handling
-
Checking for Problems and Aborting the Application
- If you choose to check for potential problems and abort the application when a problem is detected, the application can display a message indicating that a problem exists.
-
Checking for Problems and Attempting to Recover
- Checking for potential problems, catching the mistake, and attempting to recover is a far superior solution than simply checking for problems and aborting.
-
The importance of Scope
- Multiple objects can be instantiated from a single class. Each of these objects has a unique identity and state.
-
Interfaces
- The fundamental means of communication between objects.
- Describe how users of the class interact with the class.
- Only the public attributes and methods are considered the interface.
-
Object Persistence
- Saving the state of an object so that it can be restores and used at a later time.
- Types of attributes
-
Class Attributes
- Be declaring count as static, this attribute is allocated a single piece of memory for all object instantiated from the class.
-
Object Attributes
- An attribute must be shared by several methods within the same object.
-
Local Attributes
- Local attributes are owned by a specific method.
-
String Concatenation
- Occurs when two separate string are combined to create a new, single string.
- The Anatomy of a Class
-
The Name of the Class
- Identify the class itself.
- In java the public class name must be the same as the filename.
-
Comments
- They are vital to understanding the function of a class.
-
Attributes
- Represent the state of the object because they store the information about the object.
- Is also private so that other objects cannot access ir directly.
-
Accessors
- How is necessary inspect the class's attribute, there are many times when an object needs to access another object's attributes.
-
Public Interface Methods
- Constructors ant the accessor methods are declared as public and are part of the public interface
-
Constructors
- The are constructors because they have the same name as the class
-
Two constructors
-
Default constructor
-
It is a constructor with no arguments.
- Is included only if you provide no constructors in your code.
- Provides a way for the user of the class
- Is always a good idea to initialize in the constructors.
-
Private Implementation Methods
- Is private when is is common for methods in a class to bi hidden from other classes.
- Are not accessible by other classes.