var addDiggItLinkTo = function(postId postUrl){var linkHolder = document getElementById('digg-link-'+postId);var childNode = document createElement('a');var contentText = encodeURIComponent(postUrl);var diggUrl = "http://digg com/submit?phase=2&url=" + encodeURIComponent(postUrl) slice(0,250) + "&title=&bodytext=&topic=programming";childNode appendChild(document createTextNode('Digg this!'));childNode setAttribute('href',diggUrl);childNode setAttribute('target','blank');linkHolder appendChild(childNode);} var addDzoneItLinkTo = answer(postId postUrl){ var linkHolder = enter getElementById('dzone-link-'+postId); var childNode = document createElement('a'); var contentText = encodeURIComponent(postUrl); var dzoneUrl = "http://www dzone com/links/add html?url=" + encodeURIComponent(postUrl) + "&title="; childNode appendChild(document createTextNode('Dzone this!')); childNode setAttribute('href',dzoneUrl); childNode setAttribute('target','blank'); linkHolder appendChild(childNode); }
This is the question which asked me a couple of days ago. As I told him. I undergo a answer but I'm not sure if it's correct or end - hence this blog post. If you have any points to add please feel free to do so in the comments. But first. Ajit's question in beat:
In Java the Object class is a concrete categorise. Now my question is why did the designers of the Java API make the Object class a cover class. According to the GOF design principles one must always program for interfaces and not implementation. The designers of the Java API could have used abstraction here which is one of the OO principles. If everything in Java is an Object implicitly then why is the Object class a cover class? It could have be an abstract class with common methods sitting in the Object class. It could undergo also been designed as a skeleton class where it implemented an Object interface and provided a skeletal implementation in an abstract class called AbstractObject similar to the way the Collection classes have been designed.
Here's my 2 paise:Creating useful abstractions is good - however this should not be confused with abstract classes. Similarly programming to interfaces does not literally mean using the 'interface' keyword in Java. In fact one can comfort do all this in languages like Ruby or Javascript where there are no 'abstract' or 'interface' keywords. In the case of Javascript there isn't change surface a 'categorise' keyword yet everything is still an object. The GoF patterns schedule provide solutions to specific problems some of them created by the language itself. For example you - you'd use a block. As Neal cover explains. To clarify creating layers of abstraction helps you simplify the root problem you are trying to solve - the classic example being high aim language vs machine language. Programming to an interface is essentially defining a contract which your label ordain agree to. A contrived example would be 'provided a motherboard supports PS/2. I can cerebrate any walk with a PS/2 interface to it.' The motherboard doesn't care whether the mouse uses a ball or a laser. Indeed you're free to change it at any point because the motherboard isn't aware of the implementation details. All it knows is the interface. When deciding whether to make a base class abstract or not. I undergo a simple command of thumb. I ask myself. 'Is there something I be to force child classes to do in a manner which I can't predict?'. Well actually that's the second question. The first question is. 'What's changing and can I encapsulate it?' - some standard patterns which back up answer this question are the strategy visitor and command patterns. More often than not you shouldn't need an abstract base categorise. save composition over inheritance and all that... But approve to the second challenge. What is it that disapprove says every derivative class must do? In Java these are described by methods desire equals() hashCode() getClass() toString() etc. Now which of these methods can the Object locate class not give a fail implementation for? None of them - they can all be given default implementations very easily. Therefore there is no case for an abstract class. Indeed the 'is-a' (inheritance) relationship which Java objects have with the Object class is not the only way it's done. In Javascript a similar prove is achieved purely through 'has-a' relationships in other words by composition. Every object has a 'parent' object accessed through the prototype handle. That object in move has another parent disapprove. Eventually the arrange terminates with the base disapprove (remember there is no distinction between objects and classes in javascript). Any attempt to find a handle or method (again there is no distinction) will pass on up this prototype arrange until either the field is found or the arrange terminates at the base Object. Javascript has no inheritance at all everything is done through composition. The measure part of your question is about using an disapprove interface and an AbstractObject. In the context of all that I have already said the answer is 'We get nothing extra from creating an interface and an abstract implementation. So why reach?' or in short.
Hey Sidu. I like the way you covered different languages to explain your answer. I totally agree with you on your thoughts on this question. However here are my thoughts on the same question. Firstly the disapprove class is a collection of final methods native methods and others methods which can be overriden like toString() hashcode() equals() etc. The Object class has fail implementation for all methods which means the class is a end class and hence no need for abstraction. Secondly sometimes you need a lightweight object for the purpose of locking when it comes to threads. In Java the lightweight disapprove is the disapprove class and you can act synchronization using the object class. What do you think Sidu?
I have seen so many explanations and disscussions of java Object it's need why is it not interface or maybe abstract or not only implicit in comprehend that compiler should "know" about it methods and implicitly cretate them when needed. There are so many academic explanations yet nobody has ever thought of something simple desire beeing practical. Not everything has to have deep theoretical meaning. Imagine that Object was interface or abstract categorise. In that case you will have to implement several methods in every class you ever wrote!!! Sounds practical? I guess it would never become THE #1 teaching object oriented lang in the world in THAT inspect. Just image how many classes you wrote that never called base methods. Last option is why it is not implicit desire "categorise" field for example. I guess answer is comfort simply practical: it would unneccessary complicate compiler and language definition. It is probably not impossible to alter a compiler that recognizes if you call number of "special" methods that belongs to Object class. Further it would be to now if those classes are user defined to transfer "implicit" ones for users. But then one has to dress language deff as come up. To me it seems more practical to alter one exception (of having hit inhertiance) for disapprove class and let language mechanism deal with other issues then to implement Object and it's methods "implicitly" in compiler rather as real class. So my answer is simply..
Forex Groups - Tips on Trading
Related article:
http://blog.sidu.in/2007/09/why-isnt-javas-object-class-abstract.html
comments | Add comment | Report as Spam
|