Skip to main content
added 16 characters in body
Source Link
user150904
user150904

My requirements are:My requirements are:

Domestic Implementation:Domestic Implementation:

International Implementation:International Implementation:

Use:Use:

My requirements are:

Domestic Implementation:

International Implementation:

Use:

My requirements are:

Domestic Implementation:

International Implementation:

Use:

added 95 characters in body; edited tags
Source Link
user150904
user150904
    public final class Domestic implements StudentStatus {

       private final StudentType type;
       private final Collection<String> documents;

       public Domestic() {
           this.type = StudentType.Domestic;
           this.documents = Collections.emptyListunmodifiableList(new ArrayList<String>(documents);
       }
    
       @Override
       public Collection<String> retrieveDocuments() {
           return this.documents;unmodifiableList(new ArrayList<String>(documents);
       }

       @Override
       public StudentType retrieveStatus() {
           return type;
       }
   }
    public final class International implements StudentStatus {
            
       private final StudentType type;
       private Collection<String> documents;
    
       public International(Collection<String> documents) {
        
           this.type = StudentType.International;
           this.documents = Collections.unmodifiableCollectionunmodifiableList(new ArrayList<String>(documents));
       }

       @Override
       public Collection<String> retrieveDocuments() {
           return Collections.unmodifiableCollectionunmodifiableList(new ArrayList<String>(documents));
       }

       @Override
       public StudentType retrieveStatus() {
          return type;
       }
    }
    public final class Domestic implements StudentStatus {

       private final StudentType type;
       private final Collection<String> documents;

       public Domestic() {
           this.type = StudentType.Domestic;
           this.documents = Collections.emptyList();
       }
    
       @Override
       public Collection<String> retrieveDocuments() {
           return this.documents;
       }

       @Override
       public StudentType retrieveStatus() {
           return type;
       }
   }
    public final class International implements StudentStatus {
            
       private final StudentType type;
       private Collection<String> documents;
    
       public International(Collection<String> documents) {
        
           this.type = StudentType.International;
           this.documents = Collections.unmodifiableCollection(documents);
       }

       @Override
       public Collection<String> retrieveDocuments() {
           return Collections.unmodifiableCollection(documents);
       }

       @Override
       public StudentType retrieveStatus() {
          return type;
       }
    }
    public final class Domestic implements StudentStatus {

       private final StudentType type;
       private final Collection<String> documents;

       public Domestic() {
           this.type = StudentType.Domestic;
           this.documents = unmodifiableList(new ArrayList<String>(documents);
       }
    
       @Override
       public Collection<String> retrieveDocuments() {
           return unmodifiableList(new ArrayList<String>(documents);
       }

       @Override
       public StudentType retrieveStatus() {
           return type;
       }
   }
    public final class International implements StudentStatus {
            
       private final StudentType type;
       private Collection<String> documents;
    
       public International(Collection<String> documents) {
        
           this.type = StudentType.International;
           this.documents = Collections.unmodifiableList(new ArrayList<String>(documents));
       }

       @Override
       public Collection<String> retrieveDocuments() {
           return Collections.unmodifiableList(new ArrayList<String>(documents));
       }

       @Override
       public StudentType retrieveStatus() {
          return type;
       }
    }
added 9 characters in body
Source Link
mdfst13
  • 21.7k
  • 6
  • 33
  • 68

To recover from yesterdaysyesterday's disaster, I re-read the SOLID principles and refactored my code. HopfullyHopefully I did a better job than yesterday. I wanted to keep my StudentStudent class immutable, but that meant I would have to change the class everytimeevery time a new StudentStudent type was introduced, that violated the S in SOLID. Here is what I came up with.

Goal: Keep the StudentStudent immutable without violating SOLID.

To recover from yesterdays disaster, I re-read the SOLID principles and refactored my code. Hopfully I did a better job than yesterday. I wanted to keep my Student class immutable, but that meant I would have to change the class everytime a new Student type was introduced, that violated the S in SOLID. Here is what I came up with.

Goal: Keep the Student immutable without violating SOLID.

To recover from yesterday's disaster, I re-read the SOLID principles and refactored my code. Hopefully I did a better job than yesterday. I wanted to keep my Student class immutable, but that meant I would have to change the class every time a new Student type was introduced, that violated the S in SOLID. Here is what I came up with.

Goal: Keep the Student immutable without violating SOLID.

added 17 characters in body
Source Link
user150904
user150904
Loading
edited body; edited title
Source Link
200_success
  • 144.2k
  • 22
  • 188
  • 473
Loading
deleted 8 characters in body
Source Link
user150904
user150904
Loading
Source Link
user150904
user150904
Loading