Regards,
Pho
Regards,
Pho
Originally posted by Don Kiddick:
Actually, I'm not quite sure if this is exactly the Decorator pattern.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Pho Tek:
In traditional OO, you would certainly use "extends".
But I want to avoid using inheritance.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Warren Dew:
Actually, there are many experts, perhaps a majority, who think inheritance is what it's about. This is especially true in academia and certain specialized fields like robotics.
It's just that experts who feel that way tend to avoid languages that are limited to single inheritance, so we don't hear from them much in the Java world.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Regards,
Pho
Originally posted by Ilja Preuss:
To me, multiple inheritance hardly is the main issue. Implementation inheritance simply is a technique that results in stronger coupling and less opportunity for reuse. Sometimes it's worth it, often not. A "nice" example for the latter is having java.util.Stack inherit from java.util.Vector. (In fact this can't even be justified by an "is-a relationship"...)
Make visible what, without you, might perhaps never have been seen.
- Robert Bresson
Originally posted by Gerald Davis:
Inheritance implemented wrongly can lead to ugly dependences and fragile trees.
Keeping methods small and making them static is the best way of reuse.
Keap it simple.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Ilja Preuss:
[QB]
I still don't understand what making them static buys you, though. It certainly isn't much simpler to say
Foo.doSomething()
than to say
new Foo().doSomething()
The latter, though, has an important advantage: it allows us to decouple the "what" (doSomething) from the "how" (implementation of Foo), for example by instantiating Foo at a different place.
[QB]
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Originally posted by Gerald Davis:
How about
doSomething() //a form of static method called a function.
It is a prime example of decoupling "what" from the "how" ,no?
doSomething() function can implement one or many classes without the end user ever knowing about it.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Originally posted by Warren Dew:
Exactly the same argument applies to constructors, which are required to use nonstatic methods. In your example, a call to:
is just as bound to the MyThing class as
would be, and the static version has the advantage of being clearer and more efficient.
I think there's a place for both static and nonstatic methods.
If you're dealing with an integer object, you want to be able to say "integerObject.toString()", but if you're dealing with a primitive integer, it's better to be able to skip boxing it, instead saying, "Integer.toString(intValue)".
By the way, I think some of the java.util.Collections functions illustrate how static methods can actually reduce coupling rather than increasing it. For example, by having the static synchronizedMap() method, any new Map subclass can automatically be synchronized. This makes it easier, not harder, to switch to a new Map subclass, because you don't have to worry about modifying the implementation of the new Map subclass to make it synchronized.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Warren Dew:
It's not just a matter of taste. Java has beeen my primary language long enough that I write and read the former more than the latter, and I still find the latter clearer.
I believe that's because the former introduces an extraneous concept: the "new" in the former implies there's memory being allocated
and an object being created, which is entirely unrelated to what we are trying to do. The new object, which is never again used, is junk - and it's not just syntactic junk, it's semantic junk.
You might have gotten so used to it that you subconsciously ignore the fact that an object is being created - so in that sense, it might be a matter of getting used to it - but it would be better if one didn't have to get used to it in the first place.
I agree in cases where you actually want to instantiate an object. My fundamental argument is that the latter is preferred when conceptually, one doesn't want to instantiate an object at all. Having no instantiation at all makes execution even cleaner than allowing execution to proceed separately from instantiation.
As I've demonstrated in my responses to Stan, in Java you always end up programming to a concrete implementation one way or another.
I think that the agile concept of not programming for needs that haven't happened - and may never happen - is relevant here.
I think it's a waste of time to worry about polymorphism that one may never need. It's better to refactor the code later to account for it when - and if - it's actually needed.
arbitrary static methods can dispatch to implementations determined at runtime from a configuration file just as Stan suggests for factory functions.
I don't think it would be an improvement to have to call System.getInstance().getProperty("line.separator").
What does this have to do with reusability? If I can just invoke a quickie static method, I'm likely to use it. If I have to go to the trouble of constructing a potentially complex object - in this case, a System object, or even a Properties object - it's more likely to be quicker for me to write my own method instead of reusing the one that already exists.
I agree some of the arguments would change in a language without primitives. I do think, though, that there's a reason such languages haven't made the mainstream, at least not yet.
Er, it's not a false dichotomy at all
Compare how cleanly this works with Java collections, which use the static method approach, with the java.io package, where you have to use straight wrapper classes. Because the java.io package was never organized rigorously enough to put together a set of static convenience methods like the Collections class, you have weird anomalies like having to use BufferedReader to read lines, even though a BufferedWriter won't write lines; you need a PrintStream - from an entirely separate inheritance hierarchy - for that!
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
To me, in it's simplest form, the cost of polymorphism is low enough that it's almost always worth it. Of course you can go over the top - there have been teams that ended up having Factories for Factories for Factories for every single business class, which is without question overkill.
Constructors should be dead simple. Complex assemblies, especially AGGREGATES, call for FACTORIES.
Regards,
Pho
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Originally posted by Gerald Davis:
I told me that static methods are good then I found this website. http://www.javaworld.com/javaworld/javatips/jw-javatip107.html
I consider �new� command to be a low-level command and should be treated as such.
Imagine how awkward it would be if calculus, music notation, formal method even SQL(to a limited extent) was object oriented. Imagine using Electrodynamics in anything other then relativistic notation.
Sometime we need the help of domain experts in our project, but most of those experts don�t know anything about object orientation, but object orientated technology seems to be mixed with domain specific things.
2+2 or any complicated mathematics we don�t want to think allocating memory we want to get a job done and any notion of allocating memory should be hidden away.
In some Systems for example like airline booking system, there are object entities like Customers, Planes and airline companys. Isn�t the other functionality just static processes that just work on these objects to change, create or remove them.
Yes, some static processes might require the explicate use of object initiation to work but unless they are to do with the business domain objects (in this example Customer, Plane and airline Company) I would see those processes are badly designed.
Object allocation and other low-level functionality should be the domain of reusable libraries, frameworks and toolkits who might use low-level languages like C++ or Java, not application construction experts whose only interest is to bind these libraries together to build the final application.
The advantages are clear: The EJB container and the high-level languages implementation could change and improve without effecting the domains specific code.
Python: Cuts through the crap , no distraction.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Originally posted by Ilja Preuss:
And in Java 5 it wouldn't be too much effort to write your own static method and Range class so that you could write quite similar code (not fully similar, as Java is manifestly typed, whereas Python is implicitly typed):
Originally posted by Ilja Preuss:
I somehow can't connect to this vision of how work should be divided between roles. Are you acually working that way? Can you tell us a little bit more?
Originally posted by Ilja Preuss:
What, for you, is the goal of a good design?
Originally posted by Ilja Preuss:
Interestingly, in Smalltalk, "2 + 2" creates an instance of (if I remember correctly) SmallInteger with the value '2' and calls the method '+' on it with the argument of another SmallInteger.
Originally posted by Ilja Preuss:
I do know persistence layers, though, that present an object oriented facade to SQL, and think of them as being quite elegant (Toplink comes to mind).
Yes, of course, and I accept that blame. In fact, i covet that blame. As does this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|