OOP 101
John Whish
25.03.2009
Beans Means...
The term bean simply refers to an object that holds data which is available via getters and setters.
A Value Object (aka Data Transfer Object) is a bean
A object with behaviour is a bean
A static class is not a bean (doesn't hold data)
UML
UML stands for Unified Modeling Language
It is a visual way of designing applications without writing code.
There are multiple types of diagram, we will be using the class diagram in this presentation.
So what does it look like?
UML Class Diagram
You can...
Omit the return type if it is "void"
Specify arguments and their data type
Encapsulation
Basically encapsulation means hiding the inner workings of your class.
Advantages
The calling code doesn't know about the implementation or the data that is being manipulated only the methods available.
This means that you can completely change the code in your class without it affecting any calling code.
Inheritance
Inheritance allows sub (or child) classes to inherit all the properties and methods of the super (or base) class.
Inheritance
Let's model this with some code!
Interfaces & errr Interfaces
It is important to note that there are two different uses of the word "interface". Don't confuse the two (like I did when I started learning OO)
An interface is the public methods of your class. You can think of the interface as the API.
An interface also refers to a definition of the methods your class must have. This type of interface (cfinterface) ensures that all classes that implement the interface have the same method signatures.
Method Overriding
With Inheritance you may end up in a situation where an inherited method needs to work differently in a particular sub class.
Let's look at a contrived example!
Method Overriding
BookProduct.getSku() could use the ISBN
Talking to your parents is super
When you override a method, you may want to be able to access the original method in the super class.
You can not access the super method from outside your object.
Let's look at an example
Composition
An object can be made up of other objects.
For example, a (typical!) car consists of:
4 wheels
1 engine
4 seats
etc
The car object, needs the other objects to work. It is the composition of it's parts.
Composition
In our on-line shop, the Product is composed of a Supplier. This is indicated with a solid diamond.
Aggregation
Aggregation is the weaker form of Composition, where the object doesn't need the other objects to work.
A Car can have an driver, but it can still exist without one.
Aggregation
A Shopping Basket is aggregated with Product
Polymorphism
Polymorphism is a really powerful and useful aspect of writing OO code.
It simply means that you can substitute objects which have a common super class and the code will still work.
Sounds good? Let's see it in action by adding our DVD and Book Products to a Basket which expects a Product.
Resources
This presentation and code samples can be seen at:
http://www.aliaspooryorik.com/presentations/oo/part2/
Blue Nile Reviews & ratings to help you decide before purchasing Blue Nile diamonds. Write your own Blue Nile feedback here.
Posted By: Blue Nile Reviews On: 03/12/11 12:58 PM