Just to add to the idea of 'analyzing objects around', one technique
to use is "noun extraction" and "verb extraction":
- Anything you can describe easily with a noun (i.e. a naming word)
becomes a class, and potentially objects too. So to continue with the
car example we can be pretty sure that any description of the program
or system we're creating is going to mention Cars, Sports Cars, Super
Cars, Family Cars etc. and we would form some ideas of how to build a
relationship between these classes.
- Anything described readily using verbs (i.e. action/doing words)
will usually be implemented using behaviour, which in Java mostly
concerns methods (and we usually put these within relevant objects).
For cars we have things like 'accelerate', 'brake', 'refuel' etc.
- You may also come across words or phrases that describe
characteristics, and these will often become fields inside the
relevant objects. For a description of the car system I'd expect to
see characteristics like 'colour', 'top speed', 'price' etc.
Of course noun and verb extraction don't really help if your
description is missing some key details, but it can be a good starting
point.
On 17/12/2009, at 4:17 PM, Ali Shakiba wrote:
> Hi;
> Maybe I am wrong; but these are formal definitions; before going
> further; identifying the relation between objects has no standard
> way and there is a big part for human's point of view and the
> application; so no standard output.
> For object-oriented; i use the book
> Object-oriented analysis and design with applications / Grady
> Booch...[et
> al.]. — 3rd ed. --- 2007
> On page 67 in chapter 2; it defines polymorphism as the following:
> Polymorphism is a condition that exists when the features of dynamic
> typing and
> inheritance interact. Polymorphism represents a concept in type
> theory in which a
> single name (such as a variable declaration) may denote objects of
> many different classes that are related by some common superclass.
> Any object denoted by this name is therefore able to respond to some
> common set of operations.
> but for the inheritance; it is a "is a" relation. Booch categorizes
> the relation between classes as follows:
> class A is a class B ==> class A extends class B { ... }
> class A has class B ==> class A { public B bVar; ..... }
> OK. after that; if you want to use single inheritance; the sub-class
> extends a super-class; you just simply use the keyword extends. you
> can use abstract or non-abstract class for this purpose based on
> your needs. back to car example; if you do not want to have an
> object from a generic car; use abstract class for car; but if you
> want to have a minimal car; the same as generic car; just use non-
> abstract (it seems silly!).
> but for the purpose of multi-inheritance; your sub-class has more
> than one super class; java uses interfaces. I just remembered this
> note from some book; not sure which book(!); as C++ multi-
> inheritance was a good ability that could turns into nightmares;
> java doesn't allow multi-inheritance by the c++ way. it allows it by
> using interfaces.
> both ways; you can use polymorphism. in fact as i understood;
> especially from the posts above; there is polymorphism inside
> inheritance and vice verse.
> Thanks Stephen for the suggestion of analyzing objects around. I'll
> do that.
>
> OK! be happy!
> &
> With the hope of rising of Mahdi;
> Ali Shakiba
> Iran - Kerman
>
>
> On Thu, Dec 17, 2009 at 1:00 AM, Retnuh <[email protected]> wrote:
> LOL, nothing is needed.
>
> Yeah, look at everything in Java as Objects, because it is a
> complete Object Oriented Programming language.
>
> A Class creates Objects.
> Those Objects have methods (behaviors) and instance variables
> (states).
> Within the methods (behaviors) there are other variables and method
> calls.
> You can reference other objects or return objects usesing an
> object's methods.
>
>
> Any question you have, just ask and I will try to answer it as best
> as I can.
>
>
> Stephen
>
>
>
>
>
>
> nn roh wrote:
>>
>> 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
>
>
> --
> 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