When composing a song, I think it might help if I understood what some of the characteristics of a good melody might be, and do those characteristics apply generally across the board or are they specific to a given style of music. Is there a general list of these characteristics and if so, what are they?
It does depend on the style of music, but generally speaking I think there are good rules of thumb which will yield good results in most styles.
- Keep it easy to sing and easy to remember.
- You want predominantly stepwise motion. Any leaps should be smallish, or else easy to sing intervals like 5ths and octaves. Bigger leaps and/or those more difficult to sing (I think this is good advice even if the melody won't actually be sung) should be preceded and followed by contrary stepwise motion.
- The notes should mostly fit the chords. You'd be surprised how many melodies just arpeggiate a chord. Melodies can (and should) include non chord tones, but they should be in the minority, and should generally conform to the classical categories like passing note, neighbour note, appoggiatura, and suspension. But this won't matter for some styles.
- You need a contour which goes somewhere. Common contours are ascending (goes up), descending (goes down), arching (goes up, then back down), and U-shaped (goes down, then up again). These contours all go somewhere and 'tell a story'. Melodies which wander aimlessly are usually boring and hard to remember, 2 hallmarks of a 'bad' melody. That said, a lot of melodies in pop music (think Taylor Swift) are very monotonous, effectively droning on the tonic for most of the time.
- You need a focal point, a note which is either the highest or lowest or longest. Duh, technically, every melody will have a highest and lowest note. What I mean is you want to feature those notes, milking the drama out of them. Furthermore, you generally want to avoid hitting the same focal note more than once in a phrase, because doing so will erode its significance.
- Repetition, repetition, repetition. A very effective way to build a phrase is by repeating 1 or 2 basic ideas or gestures, often called motives. Repetition can be exact, or can be transposed, or inverted, or (less effectively) retrograded, and so on. The quintessential example of this motivic construction is the "ba-ba-ba-bum" from Beethoven's 5th. It is literally everywhere.
- Think about phrase structure (this is an extension of point above about contour). The 2 most common types of theme in classical music are the Period and the Sentence. You'll also find these all over in folk and pop music too. The Period is basically a phrase which ends like a question (usually a half cadence), followed by a second phrase which starts the same as the first but ends like a statement. It's an A A' structure, and can be thought of as having a call-response feel to it. In contrast, the Sentence states a unique basic idea, then repeats the basic idea in an altered form (eg transposed and/or over a different chord), then goes through a section which is less unique but characterized by a sense of motion and acceleration towards the end goal before landing on a cadence. The point is, these structures use repetition on the phrase level, and they create larger-scale cohesion. You can also think in terms of larger forms, like binary (A B) or rounded binary (A B A'). This is more about how you make a series of melodies fit together meaningfully.
- If you do something 3 times in a row, make sure the 3rd time is varied somehow. 3 consecutive identical repetitions will be boring.
I don't believe that there is any straight answer, not least because "good" itself is so hard to define. But we can give some guidelines.
First and foremost is "context". What is the melody trying to achieve? are we writing a modernist violin concerto or a comic pop song? For sheer memorability, the whistling from "Always Look On The Bright Side Of Life" (J. Altman, I believe) takes some beating - it's sheer banality makes it very successful in context. In other contexts ...
In other setting we might be interested in originality, setting a certain emotional tone, providing a vehicle for a certain artist, technical difficulty (or its opposite) and so on.
Basically, a good melody does the job it is intended to do.
That's a very broad question. There are lots of melodic ideas. (I find it difficult not to either write something that sounds disconnected or something I wrote before.) There's a pretty good book (very old-fashioned but the ideas can be applied to most modern music too): https://imslp.org/wiki/Exercises_in_Melody-Writing_(Goetschius%2C_Percy)
Good melodies tend to have mostly stepwise movement. THere needs to be enough jumps to make just scale passages not so repetitive. Outlining chords is useful too.
I believe cognitive biases commonly associated with speech perception also apply to melodies as they are literally 'pitch sentences'.
There's no straight forward answer and there's no formula - otherwise robots will write chart-topping songs for humans based on some algorithm. Some melodies sound so "good" and timeless as if they were from creation. Other melodies are just sweet for a moment but disposable with time like bumblegum. Most modern day music is like that.
As a pointer or guideline to your question about writing a "good" melody, I would say;
Music is 100% aural. So singing (whistling, humming, etc) the melody over the rhythm section is a good place to start. Thus, humanize the melody first lest it sounds machanical. The rhythm section also needs to be good and solid because that's the foundation on which the melody stands. From there, you can sing the melody over and over again until it sounds good then put it to an instrument, improvise and apply the tricks of the trade to enhance it (vibrato, slur, slides, bends, pulloffs, counterpoints, double-stops, etc). Chances are, if you hang in there for long you will stumble upon a "good" melody (at least better than what you initially started out with) . It should also be noted that a song has a life of its own. The longer you work on it, the more it evolves and takes a better form and shape. So is the melody.
It should also not go on without saying that some of the "good" melodies out there were actually "stumbled upon" and did not follow any formula. The composers never set out to write a "good" melody per se. An example will be a riff to Guns n' Roses' "Sweet Child O'mine" which came as a result of string skipping exercise which went on to become a "good" song that excited the millions if not billions around the world from generation to generation. Paul Desmond's killer melody to jazz standard "Take 5" was just a response to the 5/4 rhythm which ended up sounding good because of many factors some which cannot be formularized including the man himself behind the instrument plus the total calmniation of all his experience in expressing emotions through an instrument.
On a closing note, I'd leave you with what old time Jazzers used to say, "It Don't Mean a Thing If It Ain't Got That Swing". So make your melodies swing and your chances of stumbling on a "good" melody will increase. Good luck!