I will define science fiction, first, by saying what SF is not. It cannot be defined as "a story (or novel or play) set in the future," since there exists such a thing as space adventure, which is set in the future but is not SF. It is just that: adventure, fights, and wars in the future in space involving superadvanced technology. Why, then, is it not science fiction? It would seem to be, and Doris Lessing (e.g.) supposes that it is. However, space adventure lacks the distinct new idea that is the essential ingredient. Also, there can be science fiction set in the present: the alternate-world story or novel. So if we separate SF from the future and also from ultra-advanced technology, what then do we have that can be called SF? We have a fictitious world; that is the first step: It is a society that does not in fact exist, but is predicated on our known society -- that is, our known society acts as a jumping-off point for it; the society advances out of our own in some way, perhaps orthogonally, as with the alternate-world story or novel. It is our world dislocated by some kind of mental effort on the part of the author, our world transformed into that which it is not or not yet. This world must differ from the given in at least one way, and this one way must be sufficient to give rise to events that could not occur in our society -- or in any known society present or past. There must be a coherent idea involved in this dislocation; that is, the dislocation must be a conceptual one, not merely a trivial or a bizarre one -- this is the essence of science fiction, the conceptual dislocation within the society so that as a result a new society is generated in the author's mind, transferred to paper, and from paper it occurs as a convulsive shock in the reader's mind, the shock of dysrecognition. He knows that it is not his actual world that he is reading about.
Now, to separate science fiction from fantasy. This is impossible to do, and a moment's thought will show why. Take Psionics; take mutants such as we find in Ted Sturgeon's wonderful More Than Human. If the reader believes that such mutants could exist, then he will view Sturgeon's novel as science fiction. If, however, he believes that such mutants are, like wizards and dragons, not possible, nor will ever be possible, then he is reading a fantasy novel. Fantasy involves that which general opinion regards as impossible; science fiction involves that which general opinion regards as possible under the right circumstances. This is in essence a judgment call, since what is possible and what is not [cannot be] objectively known but is, rather, a subjective belief on the part of the reader.
Now to define good science fiction. The conceptual dislocation -- the new idea, in other words -- must be truly new (or a new variation on an old one) and it must be intellectually stimulating to the reader; it must invade his mind and wake it up to the possibility of something he had not up to then thought of. Thus "good science fiction" is a value term, not an objective thing, and yet, I think, there really is such a thing, objectively, as good science fiction.
I think Dr. Willis McNelly at the California State University at Fullerton put it best when he said that the true protagonist of an SF story or novel is an idea and not a person. If it is good SF the idea is new, it is stimulating, and, probably most important of all, it sets off a chain reaction of ramification ideas in the mind of the reader; it so to speak unlocks the reader's mind so that that mind, like the author's, begins to create. Thus SF is creative and it inspires creativity, which mainstream fiction by and large does not do. We who read SF (I am speaking as a reader now, not a writer) read it because we love to experience this chain reaction of ideas being set off in our mind by something we read, something with a new idea in it; hence the very best science fiction ultimately winds up being a collaboration between author and reader, in which both create -- and enjoy doing it: Joy is the essential and final ingredient of science fiction, the joy of discovery of newness.