How to obtain a fair recommendation letter from a professor who knows me via course, not research? The normal case is that students should obtain a recommendation letter for graduate school from the professor under whom the student has performed research.

Currently, I am taking a course conducted by a field-famous professor, from whom I wish to obtain a recommendation letter for my grad school application. However, due to some reasons, I am not able to do research under him, which implies that our only connection is that course that I am currently taking.

If so, maybe one year later, he may refuse to write me a letter, because he does not know me well, or even has forgotten me. Even if he is willing to write me a letter, being not familiar with me, he may not be able to write a decent letter for me.

(By "decent", I mean a letter that actually can help. I know that as long as he is willing to write me one, he can simply say "the student obtained a good grade from my course". I don't think this kind of letter will actually help, IMHO.)

So besides obtaining a good grade for this course and frequently asking valuable questions, what can I do to impress him so that I can obtain a decent recommendation letter for my future grad school application? How to make him understand me better?
Visit the professor and explain your plans and your wish to have him provide a letter in a brief but structured way. Slip in some of your (positive) thoughts concerning his course and, if you were inspired by it, the importance of the course for your current interest. I do not think you can do more. If the person is not interested, I doubt you can do anything to change the view that would not be annoying in the end. It is possible the person has forgotten you but if you stood out even a little in the class, my bet would be the opposite. As I see it you only risk getting a no, and not much could be done to change that.