aspose file tools*
The moose likes Beginning Java and the fly likes Abstraction and Object Oriented Programming Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Abstraction and Object Oriented Programming" Watch "Abstraction and Object Oriented Programming" New topic
Author

Abstraction and Object Oriented Programming

amit sanghai
Ranch Hand

Joined: Dec 05, 2000
Posts: 231
Hi,
I want to know what is and how do we do abstraction? How do we divide a big project into different classes in different packages using abstraction?
Anthony Villanueva
Ranch Hand

Joined: Mar 22, 2002
Posts: 1055
IMO abstraction means you get only the details that are relevant to your problem from the real-life entity, and make them the basis of your class.
For example, suppose, you want to create an abstract data type called Room. A real room contains many details but only certain aspects of it are relevant, depending on how you approach it. If you were an architect, you would probably be concerned with floor size, color, the number of windows it has, lighting, etc etc. If you were a game designer you would maybe think about what Monsters would be deployed in this room, what treasure hidden, if there are any clues/traps etc. If you were a hotelier you would be thinking about occupancy rates, how many beds, room number, etc etc.
Having determined which entities are relevant to the problem domain, you have to decide on the granularity of your class's attributes.
Furthermore, abstraction also entails presenting a public interface for your class's behavior, but hiding the actual ipmlementation of this behavior to your client.
amit sanghai
Ranch Hand

Joined: Dec 05, 2000
Posts: 231
Thanks Anthony.
I want to know about how abstraction is used to present a public interface for my class's behavior, but hiding the actual ipmlementation of this behavior to my client. May be an example would help.
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
In this example, the implementation of the calculateArea( Rectangle ) method is hidden from the user while it provides a public interface for the user to use.
Getting the idea?


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Byron Estes
Ranch Hand

Joined: Feb 21, 2002
Posts: 313
You may also want to consider the following java supports interfaces which are abstract and abstract classes. The idea behind an interface is that you define the behaviors you want to expose. You can then implement the interface in a class. The implementation is thus hidden from the client application that uses it. If you want to change the internals of the implementation class you can and the client application will not need to make any progamming changes. Obviously, you'd need to redistribute the code, but the client would not need to physcically alter his/her code that calls you class because they use the interface. Classes implementing the interface are forced to provide implementations for all the interfaces methods.
An abstract class is sort of like a interface in that some portion of it is abstract. The developer marks the class as being abstract this forces the developer using it to extend the class and provide implementations for all remaining abstract methods, while it inherits those that were concretely defined.
Regards,


Byron Estes<br />Sun Certified Enterprise Architect<br />Senior Consulant<br />Blackwell Consulting Services<br />Chicago, IL<br /><a href="http://www.bcsinc.com" target="_blank" rel="nofollow">www.bcsinc.com</a>
Byron Estes
Ranch Hand

Joined: Feb 21, 2002
Posts: 313
And since you brought up OO...
Consider how abstraction supports encapsulation and polymorphism.
We already talked about a form of encapsulation achieved by limiting the client's access to our class via an interface.
Polymorphism is also supported by providing an interface that can be implemneted by a number of independent classes. These different classes can however be treated the same with regard to the methods provided by their common interface. As a result, you can have a vector of object references of the interface type. Each reference refers to an object which is of the type interface, but each class can implement the methods differently.
Regards,
amit sanghai
Ranch Hand

Joined: Dec 05, 2000
Posts: 231
Thanks everyone. I am clear on OO concepts.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Abstraction and Object Oriented Programming