• Post Reply Bookmark Topic Watch Topic
  • New Topic

inheritance - web page objects relationships  RSS feed

 
Karina Guenther
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok this either a stupid question or a tricky one:
I am describing a web page that has several different sections that I want to create different objects so that I can organize my code better. For example:
my main 'Profile' page shares headers, footers and a right section with other pages that is called global. This 'Profile' page also has a section called 'preferences' that I want to define as it's own object.

I keep going back and forth on how I want to define the relationship between these two. While I want my preferences section to inherit navigation and webController from the Main page, it doesn't seem as if it's truly a child of the 'Profile' page...just a part of it. And if I instantiate the profile page only I may want to access the objects of the 'preferences' section.
So, is the following a valid design or is it a very bad one?

1. Have the preferences section extend the Profile page
2. have the profile page able to obtain an instance of the profile section like this:



Then I use the code like this:


 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This code contains a lot of classes that are not part of the JRE or Servlet API - WebBrowserScreen, WebBrowserController, Navigatable, ATFBrowserTestCase... - are you using some 3rd party framework? If so, which one? Does it come with documentation?
 
Karina Guenther
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The WebBrowserScreen, WebBrowserControllers etc are wrappers we've created in order to use the Selenium API that allows your code to open and navigate web browser screens. Their recommended basic pattern for writing the logic to navigate these screens and automated tests for them is called the page object pattern where basically each page is an object or if the web page is complex then sections of that page are treated as an object(s). If you're interested here's a description from the Selenium wiki, but since my question is related to the design and relationship between my Profile & preferences objects, I don't see how what the selenium classes are makes any difference.

http://code.google.com/p/selenium/wiki/PageObjects

If the profile screen didn't have so much going on, I'd put everything in that one class. Instead, I have the main page, and my section of that page extends from it, so that when my test instantiates that subsection it inherits from the parent how you navigate to that page. However, I thought, what if I'm instantiating the main page and want access to the section, so I need to be able to have the parent instantiate the child's to gain access.

So, does my design break any good coding practices?
 
Ravi Khadgi
Greenhorn
Posts: 20
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Assuming that 'Preference' is a section inside 'Profile' page, it is desirable to use Composition over Inheritance in this case. Using Inheritance would violate the Liskov substitution principle.
 
Karina Guenther
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess it comes down to your definition of 'is a'. I would say that the preferences section 'is a' part of the profile page. Just as accurate is the statement that the profile page 'has a' preferences section, which no other page will have.

In addition: when I instantiate the profile page, I may or may not need to use the preferences section. However, the preferences section will always need the 'knowledge' that the profile page has about how you navigate to that page.

So, if I understand you, I need to favor composition over inheritance which results in:


correct?


 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!