Answer the question
In order to leave comments, you need to log in
How to make a phone book task in js using OOP?
You need to make a phone book page
At the top of the window there are 3 text fields (name, phone, mail) and the add button, the
user fills in the fields and clicks on the add button
and a new contact is added to the table located under the add contact form
above the table with contacts there is a text field for search
in which the user starts typing text and the elements are filtered
in the table itself, opposite each contact there is a delete and edit button (we won’t do it now, this will be done later)
by clicking on the delete button, the contact should be deleted
The application should consist of 3 classes.
Please tell me the correct logic, in which direction to dig. Or similar examples.
At this stage, there is such a vision:
//уровень данных
class GetContact {
constructor(name,phone,email){
this.name = name;
this.phone = phone;
this.email = email;
}
};
//уровень логики
class ContactEdit extends GetContact {
//массив контактов
//методы для добавления и удаления классов
//метод для поиска по подстроке
};
//уровень графики
class TableEdit extends ContactEdit {
//метод для добавления данных в таблицу
};
function submitForm(form) {
let name = form.name.value;
let phone = form.phone.value;
let email = form.email.value;
let newUser = new GetContact(name,phone,email);
//вызываем методы классов
};
Answer the question
In order to leave comments, you need to log in
You made a repository, but you don't have a single entity. If in simple terms:
class Contact {
id
name
phone
remove()
save()
render() => `<form></form>`
}
class PhoneBook {
contacts
render() => `<table></table>`
}
There cannot be a getcontact class. A class is a description of an object.
Try to just think in terms of objects - the object of a person, the object of a phone book. Accordingly, the phone book object will have just the getcontact method, which will return an object (class instance) of a person.
Where to put the third class here - I don't know. Is it just some kind of search that can search and call the methods of the book object to render the found one.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question