A
A
Anton R.2019-09-14 16:55:33
PHP
Anton R., 2019-09-14 16:55:33

I sketched the class structure of the bulletin board training site, how to distribute the functionality even better?

In general, I sat on my procedural code and added Classes and Functions to them (without data) for the time being. I watch Eliseev, I read Zandstra and Weissfield's Object-Oriented Thinking.
This is just an approximate schematic diagram, a framework.
At the moment it turned out like this:
(some functions will accept other objects, yes, "matryoshka in a nesting doll")

// --------------- ВСЁ ЧТО КАСАЕТСЯ ПОЛЬЗОВАТЕЛЕЙ: -------------------

class User {
  public function getName(){
    // Отобразить имя
  }
  public function getPhone(){
    // Отобразить телефон
  }
}

class UserPersonalPage {
  // Личный кабинет. 
  public function displayMyAdverts(){
    // Показать мои объявления. 
    // Вызвать Объект MyAdverts, передать ему мой id для вывода моих объявлений
  }
  public function displayMyFavorites(){
    // Показать мои избранные. 
    // Вызвать Объект MyFavorites, передать ему мой id для вывода моих избранных объявлений
  }
  public function displayMyPersonalInfo(){
    // Показать мою персональную информацию - Имя, email, телефон
  }
  public function changeMyPersonalInfo(){
    // Изменить мою персональную информацию - Имя, email, телефон
    // Вызвать Объект UserService, передать ему мой id, вызвать метод изменения нужной информации
  }
}

 // --------------- ВСЁ ЧТО КАСАЕТСЯ ОБРАБОТКИ ПОЛЬЗОВАТЕЛЕЙ: -------------------

class UserService {
  
  public function addUser(){
    // Регистрация пользователя
  }
  public function deleteUser(){
    // Удаление пользователя
  }
  public function activateUser(){
    // Активация пользователя
  }
  public function changeUserPassword() {
    // Сменить пароль пользователю
  }
  public function changeUserName() {
    // Сменить имя пользователю
  }
  public function changeUserEmail() {
    // Сменить email пользователю
  }
  public function changeUserPhone() {
    // Сменить телефон пользователю
  }
}

class UserLoginLogoutService {
  // Вход и выход пользователей
  public function userLogin(){
    // Вход
  }
  public function userLogout(){
    // Выход
  }
}

 // --------------- ВСЁ ЧТО КАСАЕТСЯ ОБЪЯВЛЕНИЙ: -------------------

class AdvertCollection {
  // Список объявлений
  public function displayRecentAdverts(){
    // Показать последние добавленные объявления
  }
  public function displayPromotedAdverts(){
    // Показать объявления выведенные в топ платно
  }
}

class Advert {
  // Объявление детально
  public function displayAdvert(){
    // Показать объявление детально
  }
}

class AdvertFavorites {
  // Избранные объявления
  public function addAdvertToFavorites(){
    // Добавить объявление в мои избранные
  }
  public function displayFavorites(){
    // Показать мои избранные
  }
}

class MyAdverts {
  // Мои объявления
  public function displayMyAdverts(){
    // Показать все мои объявления
  }
}

How else, more competently, can all this be distributed? How would you do?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Maxim, 2019-09-14
@anton_reut

See further courses Eliseev. He has a lesson on project managers. Where he breaks everything into a CQRS pattern . Here is a link to the domain layer https://github.com/ElisDN/demo-project-manager/tre...
You get that UserService is a Handler or UserHandler if you keep it all in one folder. Look at the structure. I'm doing the same now and it's very easy to understand. In the UseCase folder what you need to do is:
UseCase/User/Create
In it Files:
Command.php
Handler.php
Form.php
Or like this:
UseCase/User
In it Files:
UserCreateCommand.php
UserHandler.php
UserCreateForm.php
If with regards to yours, then you do not need to repeat the name of the methods in the class. The UseServise method is just login, not userLogin
Also, the names need a little more thought. It's more convenient to call UserLoginOrLogoutServise AuthServise... It's
not clear why there are so many methods with the beginning in the name display
Implement the repository.

D
developer007, 2019-09-15
@developer007

It is not necessary to fence a bunch of classes. not necessary at all. Do you think it looks cool? Handle khuyandle ... read all sorts of Eliseevs ... maybe cool, but supporting this shit is such a thing.
make components - that is, there are several services and there is a facade that aggregates services
https://refactoring.guru/ru/design-patterns/facade
component/User/Facade.php - here you bring out the methods that you want to use everywhere.
component/User/AuthenticateService.php - here are the methods of registration, authorization, exit
component/User/SettingsService.php - here are the methods for changing the username, etc.
component/User/Entity/User.php - the entity from the database
component/User/UserRepository.php - Here are the methods of working with BP. You pass User.php to these methods
(I like to always add Service as it pleases in general. The main thing is to make it clear to other people)
you make another component
component/Adv/Facade.php - here are methods about declarations
and you also make internal services.
See that there are no cyclic dependencies.
Try to use an external EventListener - like the user logged in for the first time, you throw out this event. You catch in the Adv component and create a demo ad for it. As an example.
This way you will maintain loose coupling.

N
Northern Lights, 2019-09-15
@php666

I designed the board from scratch in OOP.
I would have written an extended answer, but I'm too lazy.
You just have to read Fowler, I told you 100 times. You don’t do this, so you write some kind of partly correct thing, but if you put it in order, you don’t understand it yourself. What do you want to achieve in architecture? In the end, you don't know where you're going. You have NO architecture and understanding of how to do it right, so you rush about. And architecture is when a step to the left, a step to the right - execution. This is when you do everything according to the agreed rules and do not ask questions, but how to do it right.

class Advert {
  // Объявление детально
  public function displayAdvert(){
    // Показать объявление детально
  }
}

some kind of game. You must operate first of all with the controller, model, view . The model is entity classes and services. In many popular frameworks, the model is entity+ActiveRecord. You can use the model + DataMapper pattern. Not the point.
What is Advert? This is an ad. This is a model. It doesn't have any displayAdvert method. This method can be on an ad controller that displays ONE ad per page.
What, according to your logic, should this method do? How is it different from the STORAGE::findById() method? It should be in AdvertCollection::findByUser()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question