bree vanoss
Posts: 9
Nickname: bree
Registered: Sep, 2002
|
|
Re: OOP Concepts
|
Posted: Sep 30, 2002 2:14 PM
|
|
Inheritance: Pro: If you have multiple "things" that are all a type of something, (farmers and fishermen are both people) you can place common logic/attributes in the "parent" class. This allows for code reuse. Con: It is possible to over-rely on inheritance, the result of which may be a tall, unweildy object model. This type of model could lead to problems if it is possible that an ancestor may need to be moved about or broken down. That doesn't make a whole lot of sense; let's say that you have this really tall model and then you find that one attribute MUST NOT BE AVAILABLE in one of the child classes, if this happens there may be quite a bit of work to refactor the super tall oblect model. Hint: use assocaition instead of inheritance.
Abstract Classes: Pro: Marking a class as Abstract basically forces it to be extended before it is a valid class that can be instantiated. They can also sorta function as an interface, in that an abstract class may be a return type from a method, so that the underlying implementation can vary based on some criteria. For example
<java> Calendar myCal = Calendar.getInstance(); </java>
could return a Calendar object that is valid for the current locale. This means that if the system's current locale is US, it would get a GregorianCalendar whereas if the current locale was JA, it may get some sort of Japanese calendar.
Con: People often get confused about when to use an interface vs. an abstract class.
Encapsulation: Pro: Encapsulation allows developers/designers to use "things" instead of having to write all the application logic from scratch.
Con: This may sounds stupid, but if people use crappy names, encapsulation can actually be a pain because you have to actually look at the class to figure out what the hell it's supposed to do.
enjoy,
-=bree
|
|