The problem with getting rid of the "undesirables" is that sooner or later someone will decide that YOU are an undesirable.
Campbell Ritchie wrote:Thank you for showing the code.
That looks like proper object‑oriented code; whoever is teaching you is doing a good job. I am pleased to see you using a record, which I think is a good option, but please explain why you chose a record. Why have you got the second record as an inner class? That looks strange. It it were an inner class, I think it is best to make it private. Your method to get the complementary strand (not compl[u]iI/u]ment) creates a new instance every time it is called. Please suggest some other ways to calculate the coplement other than using a switch‑case. You might consider a Map, if you are familiar with Maps. I don't like to see default for a normal input after case. Restrict default to abnormal cases, for example so you can throw an exception. Have cases for A, c, T, and G. Use default to signal an abnormal letter and throw the appropriate exception. Run the complement method once and once only, from the constructor. Use it to initlialise a field. Remember Strings are immutable. I hope that helps; there would be more comments if I had more time.
Campbell Ritchie wrote:
Why are you returning different types from the toString() and getXXX() methods? Give the transcription method void instead of its return type and use it to create the complementary strand field. If you give that method private access, and only call it from the constructor, then it will only be called once. Consider returning something representing both strands from toString().
That's a pleasureAlexander Santana wrote:. . . Thank you very much . . .
It is good to see you back. And it is good to see such clear explanations for design decisions.That is a good reason. . . I chose to use a record because I had just learned about them . . .

Yes. A record is (or should be) immutable, which has all sorts of advantages. Look in books like Effective Java by Joshua Bloch, and look for the section called “Minimize Mutability” or similar.Do you think a record is a good choice . . .?
You can probably do that more simply with a private field. What you are describing is the standard practice of information hiding.2- The reason I have the other RNAStrand record as an inner record is because I didn't want the outside code to have direct access to it . . .
The idea of coming to a forum is to let many people look at your code and make suggestions. If you produce more code, you will probably get more suggestions and help.. . . Thank you so much for suggesting it!
It means you cannot modify a String object. If you go through the String documentation and look for methods, you won't find any that appear to modify the object and have void instead of a return type. They all return String, which means a new object. Any modification is not your problem. If you have a String field, you can return a reference to it 1,000,000× and your users can play with it to their hearts' content. Since they always create new objects, your original cannot change, and your record is safe from such changes. That is why the documentation says Strings can be shared.. . . Strings are immutable . . . I have to avoid modifying Strings . . .
Carey Brown wrote:
Mike Simmons wrote:Or, adapting Carey's solution to use something like that nice switch expression Alexander already came up with, and also use Collectors.joining():
Campbell Ritchie wrote:. . .
Since records are supposed to be immutable, I think it is a good idea to initialise the RNA immediately, before the constructor completes, otherwise calculating the RNA will alter the state of the record object and it will become mutable. You can work a fiddle by ensuring that the RNA is only calculated once and the change can never be visible to users; you can call that functional immutability. But initialising all the fields from the cnstructor is probably an easier way to ensure immutability.
Look forward to seeing your updated version.
Yesterday, I wrote:. . . . Effective Java by Joshua Bloch, and look for the section called “Minimize Mutability” or similar.
2nd edition page 73 or 3rd edition page 80.
2nd edition page 184 or 3rd edition page 231.. . . Joshua Bloch's book about defensive copies. . . .
both of you.
Campbell Ritchie wrote:Have corrected your quote tags.
Let's throw a few random ideas into the air and see whether you like them.
It might be better to have the source strand and the destination strand fields of the same type, or nearly the same type. Maybe an unmodifiable List<Nucleotide> and you make Nucleotide into an enum. Or two enums, one with T and one with U. You can use enums as cases in switch statements or as keys in a kind of Map. This may all be beyond your current knowledge and experience.
I know it is easy to use a String as input and result, but beware of Strings. One problem you might have is that you cannot be sure that a String only contains ACTG/ACUG. I shall let you think how you can get round that with the default keyword in a switch statement. Strings do have the great advantage, as I said last night, of being immutable.
Also that I inadvertently introduced an error. I shall let you find itA few minutes ago, I wrote:. . . Note I have changed the spellings . . .
I have always been used to bases in the order ACTG/ACUG.
Campbell Ritchie wrote:
Also that I inadvertently introduced an error. I shall let you find itA few minutes ago, I wrote:. . . Note I have changed the spellings . . .
I have always been used to bases in the order ACTG/ACUG.
[edit]Also I fogrot to assign the short title in the constructor.[/edit]
That's a pleasureAlexander Santana wrote:. . . Thanks . . . Campbell Ritchie! . . .
