• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Problem with attributes in classes.

 
Greenhorn
Posts: 9
IntelliJ IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, I'm trying to build an e-commerce website and I encountered a problem.
I declared a superclass product and some sub classes like this

This is how I want my website looks like in the specification section.


After creating a sub class like I said above, I got a problem that what if the admin wants to add new product which doesnt have some attributes like internalVolume but has some attributes like color, consumptionPower? But I dont want to edit the source code everytime there is a new kind of product. Is there a proper way to solve this?
I also have an idea. It's I create a built-in text editor in admin-cp and let the admin formats all the text in attribute "specification" before inserting into the database. If this is a proper way, is there any API for creating a text editor?
Thank you for your help .
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Consider replacing those String variable with a single Map - this makes adding new "attributes" a simple process and the new attributes will not interfere with the original.

One of the virtues of this approach is that you can initialize a product from a Properties style file or an XML document.

Check out the JavaDocs for Map implementations and Properties in the java.util package.

Bill
 
No, tomorrow we rule the world! With this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic