T
T
Tatyana2015-09-29 01:34:19
C++ / C#
Tatyana, 2015-09-29 01:34:19

How to implement work with Page Component Object with the least duplication and simple support?

I build pages from blocks, by the usual declaration of aggregated pages in the form of fields. Transitions between pages sometimes go through generalized pages (delegation), sometimes directly; page methods return either themselves or another page (Flow).
But what about minor differences of some pages/blocks (and at the same time complete identity of some other pages) for authorized and unauthorized users? I tried to apply the Strategy pattern, but I still didn’t understand where to put the context class and how to use it, well, in the algorithms themselves for an authorized and unauthorized user, I don’t understand what to write. Now I have the usual if / else and the IsLogged() method (+ the GoToLogin(AccountData accountData), GoToLogout methods), and also, in fact, some blocks have a replacement for authorized users (for example, there is a HeaderForLoggedUser with the "Logout", "Cart", "My Profile" and its analogue HeaderForUnLoggedUser, which has only a "Sign in" button).
Also, for authorized users, there may be a couple more block pages on the aggregating page than for unauthorized ones.
What is the best way to implement all this? I tried to redo the example with inheritance from AuthTestBase or just TestBase, it didn’t help, then I started looking towards two different ancestors of AuthPageBase and PageBase, but also a dead end. The option with many classes for pages seems easier anyway..
I can’t understand whether it is necessary to make some kind of static field with the data of the user account under which I logged in, and whether it is necessary to periodically check that I am logged in under the given “Vasya”, and not just under someone else? How is this implemented if I still decide to do something like this? Add a property with account data to each block page + a method that checks under which user I am authorized and relogin under the one I need, if I am logged in the wrong one?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question