So nice m i will start from now to convert every thing to objects and to find the relation between them
Ok Stephen, how much you want for this explanation ? LOL! just kidding :) Thanks & best wishes, Nada On Thu, Dec 17, 2009 at 12:03 AM, Retnuh <[email protected]> wrote: > 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: > > Thank you all , ii have been read your posts , its really helpful :) > What i am looking for is more practical examples that help me to think > better with oop . > > regards, > > Nada > > On Wed, Dec 16, 2009 at 11:16 PM, Retnuh <[email protected]> wrote: > >> Do you know what a Class is? An actual Concrete Class that is used to >> create objects. >> If you know about that, then an Abstract Class is a Class that is not >> Concrete, meaning it does not create objects. I has all the same features a >> normal (concrete) class has, but it has the keyword "abstract". In an >> abstract class, you are allowed to have methods that are not defined with >> the logic inside them; except just simply defined like: public void >> setName(String name); >> Now for an Interface. You can only define the method and attributes >> (instance variables) like: public String name; public int age; public >> String getName(); and so on. Then you can implement an Interface and/or >> extend an Abstract Class. >> See the good thing about Interfaces are, you can implement numerous ones. >> You can only extend one Class whether it is a Concrete Class or an Abstract >> Class. >> However, if you implement an Interface, you must.... MUST define (use) >> every method within your Class that implements it/them. >> >> Now if you need help explaining why you would use an Abstract Class or an >> Interface; well that is because of Inheritance, Abstraction and >> Polymorphism. First learn what those three things mean and then look into >> Abstract Classes and Interfaces. >> >> What I have just told you here is the cut and dry of the meanings of both. >> But now you have a good understanding of the differences of them, so read >> more on these two and soon.... You will be a Coding Phenomenon <-- I know >> this is Corny, but hey... You need excitement and a giggle here and there. >> >> Stephen >> >> >> >> nn roh wrote: >> >> Hi all, >> >> Thanks a lot for sharing ideas and help in this group :) >> >> I want more examples on using abstract classes and interface ... ? >> >> Thanks, >> >> -- >> 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 >> >> > -- 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
