|
Think of anything inside your house. Then relate
them to Objects in OOP. For instance. Do you have a car? If you do not have one, lie to me and say you have the baddest car known to man and that it is a Bugatti Veyron (my favorite car). Think of this car as an object hat has many objects right.... The car is an object. Right? This Bugatti Veyron shares similar states and methods with other cars. Right? So it is safe to say you could have another Class (object) called a Car Class. Hence the Inheritance of OOP. The Bugatti Veyron will inherit those similar things from this class. We will make it an Abstract Class, because we do not want Generic Cars running around. We only want Bad Ass cars that are produced from a Car Manufacter and have been named. Okay, we have Inheritance done by using an Abstract Class. Now we want to use an Interface. Well same thing goes here with we can not create an object from an Interface. But we can use an Interface when objects share certain methods or states. But with an Interface, the methods can all be differently implemented. So you have a Brake System Interface that is used by all cars. Well the Brake Interface is used differently in a Veyron than a Honda Accord. Right? The Veyron has Wings that deflect the wind to help stop it when the brakes are applied. Well with an Interface we only declare the methods (public void stop();) and only declare the instance variables (private int speed;). This way each class that implements the Interface can use it how it needs to. Here is the kicker with Interfaces though. You can use it in methods that will return an object that implements it. You follow that? Polymorphism. This means.... public void purchaseCar(BrakeInterface car); This method will take as a parameter any car object that implements the BrakeInterface. Just as this method will return an object that implements the same Interface: public BrakeInterface getCar(); So you have the Car that has thousands of object all within it, Right? You have a window, you have a seat, you have a steering wheel. These are all objects them self and they all have states and behaviors. They are black (state) they move up and down (behaivors). So all these have OOP. Abstraction = You think of this car that holds all these other objects simply as a car and not as a Steering Wheel + Seat + Windows + brake + gas + engine.... you get the point. You think of the car as one object and not all the thousands of objects that make it up. This is Abstraction.... Well, I should have got paid for all this.. LOL No, this is what I have learned and I will help anyone. I didn't have anyone to help me most of the way and I wish I did, so this is why I will help. Stephen nn roh wrote: -- To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/javaprogrammingwithpassion?hl=en |
- [java programming] Obstruct class vs interface nn roh
- [java programming] Re: Obstruct class vs interfac... علی شکیبا
- Re: [java programming] Obstruct class vs interfac... Retnuh
- Re: [java programming] Obstruct class vs inte... nn roh
- Re: [java programming] Obstruct class vs ... Retnuh
- Re: [java programming] Obstruct class... nn roh
- Re: [java programming] Obstruct ... Retnuh
- Re: [java programming] Obstr... Ali Shakiba
- Re: [java programming] O... Nic Fox
- Re: [java programming] O... nn roh
- Re: [java programming] O... Nic Fox
- Re: [java programming] O... nn roh
- Re: [java programming] O... NISHANT BULCHANDANI
- Re: [java programming] O... nn roh
- Re: [java programming] O... Stephen Hunter
