Help understanding this code:

DTO CLASS:
package dto;

import java.util.Objects;

public class Dto<K> {
protected K key;

protected Dto(K key) {
this.key = key;
}

public K getKey() {
return this.key;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || this.getClass() != o.getClass()) {
return false;
}
Dto<?> dto = (Dto<?>) o;
return dto.key == this.key;
}

@Override
public int hashCode() {
return Objects.hashCode(key);
}
}
package dto;

import java.util.Objects;

public class Dto<K> {
protected K key;

protected Dto(K key) {
this.key = key;
}

public K getKey() {
return this.key;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || this.getClass() != o.getClass()) {
return false;
}
Dto<?> dto = (Dto<?>) o;
return dto.key == this.key;
}

@Override
public int hashCode() {
return Objects.hashCode(key);
}
}
Repository class:
package repository;

import dto.Dto;

import java.util.List;

public interface Repository<T, K extends Dto<T>> {
void add(K item) throws RepositoryException;
void remove(T key) throws RepositoryException;
K get(T key);
List<K> getAll();
boolean contains(T key);
}
package repository;

import dto.Dto;

import java.util.List;

public interface Repository<T, K extends Dto<T>> {
void add(K item) throws RepositoryException;
void remove(T key) throws RepositoryException;
K get(T key);
List<K> getAll();
boolean contains(T key);
}
Dao class:
package repository;

import dto.Dto;

import java.util.List;

public interface Dao<T, K extends Dto<T>> {
void insert(K item) throws RepositoryException;
void delete(T key) throws RepositoryException;
void update(K item) throws RepositoryException;
K get(T key);
List<K> getAll();
}
package repository;

import dto.Dto;

import java.util.List;

public interface Dao<T, K extends Dto<T>> {
void insert(K item) throws RepositoryException;
void delete(T key) throws RepositoryException;
void update(K item) throws RepositoryException;
K get(T key);
List<K> getAll();
}
16 Replies
JavaBot
JavaBot10mo ago
This post has been reserved for your question.
Hey @userexit! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
userexit
userexitOP10mo ago
Repository is supposed to handle the logic for accesses so for example not add an item thats already added in the list etc Dao = data access object is supposed to do the physical job of adding, deleting, updating objects Dto<K> is supposed to define a certain key of type K that an object will use for identification lets say I have a studentclass that uses an integer as a key to identify a student StudentDto extends Dto<Integer> With this knowledge the code:
public interface Repository<T, K extends Dto<T>>
public interface Repository<T, K extends Dto<T>>
means to try to add, remove, update elements from a data list of data transfer objects, I must specify the T = type of key, and a class that uses that key as an identificator right ? thats waht it means right ? so StudentRepository implements Repository<Integer, StudentDto> with StudentDto extends Dto<Integer> StudentDto extending Dto<Integer means he uses as a key an Integer and here I say, hey StudentRepository is going to implement Repository and the key is an Integer, and the class that uses that key for identification is StudentDto is this what it means ?
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
userexit
userexitOP10mo ago
noted
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
userexit
userexitOP10mo ago
okay and besides that is my understanding of this right ?
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
userexit
userexitOP10mo ago
OI didnt write this codej ust trying to understand it is it a functional interface
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
userexit
userexitOP10mo ago
so this here replacs my Dto<K> class T extends IdentityKey<K> does this still work when using interfaces im asking because of extends keyword
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
userexit
userexitOP10mo ago
alright I see but besides that my explanation of repository etc was it right also since ur here
url = getClass().getClassLoader().getResource(FILE_URL).getFile();
url = getClass().getClassLoader().getResource(FILE_URL).getFile();
can u maybe explain this code
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
userexit
userexitOP10mo ago
I didnt quite get this: PECS (provider extends, consumer super) T here is a parent of Blarg I can get that much
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
JavaBot
JavaBot10mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.

Did you find this page helpful?