Page 1 of 2 12 LastLast
Results 1 to 20 of 24
  1. #1
    DoubleDee is offline Member
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    28
    Rep Power
    0

    Default Want to use OOP on my website

    Hi, I have been programming for many years but never really learned object-oriented programming (OOP) beyond text-book examples.

    I have LOTS of questions.

    My end goal is to understand OOA/OOD well enough to code a modest website that uses solid OO practices, and maybe even some Design Patterns.

    Right now I would like to build a simple website that allows users to register and then log-in.

    Question:
    - For a beginner like me, can I hard-code the HTML pages, and then just have Classes/Objects to take care of the business logic?

    (Or to do an OOP website, does the OOP even create the webpages dynamically?)

    I have lots more to ask, but maybe that is a question to break the ice?!

    Sincerely,


    Debbie

    P.S. I won't actually be using Java, but figured Java and C++ developers are some of the best, so I decided to get OO help here! :)

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    First of all, welcome to Java Forums. :)

    Actually OO is a wide area. In simple words I can say that it's all about keep your application separately looking at the different views of, to be more clear to change in later time. It'll take a long time to be solid in OO concept in my experience. It's not much simpler as I told you actually.

    As you tried to do that, you can keep the UI, business logic, data layer and so on separately from each other, yet communicate to provide the required functionality. In that simply you can any changes to the application in any time. More important thing is that, because none of the application be successful at the first release. In OO there is noting to do with static/dynamic content specifically. I'm not clear enough that what you mean by the OOP Website too.

    Did you get a basic idea or I've confused you? :)

  3. #3
    DoubleDee is offline Member
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    28
    Rep Power
    0

    Default

    Quote Originally Posted by Eranga View Post
    First of all, welcome to Java Forums. :)

    Actually OO is a wide area. In simple words I can say that it's all about keep your application separately looking at the different views of, to be more clear to change in later time. It'll take a long time to be solid in OO concept in my experience. It's not much simpler as I told you actually.

    As you tried to do that, you can keep the UI, business logic, data layer and so on separately from each other, yet communicate to provide the required functionality. In that simply you can any changes to the application in any time. More important thing is that, because none of the application be successful at the first release. In OO there is noting to do with static/dynamic content specifically. I'm not clear enough that what you mean by the OOP Website too.

    Did you get a basic idea or I've confused you? :)
    You help me with OOP and I'll help you with English! ;)

    I think I got the gist of what you were trying to say.

    Yes, I already am familiar with the concept of separating the "presentation layer" from the "application layer" from the "data layer". (Although don't force me to use the MVC model, because I think it isn't as well understood as many "experts" claim it is.

    What I mean by "OOP website" is a webiste where the behind-the-scenes code using an Object-Oriented approach as opposed to a Procedural approach.

    As far as OOP and content, what I mean is this...

    In theory, you could write an ENTIRE website where everything is created at run-time by Classes including even the HTML?! :eek:

    After all, PHP, JSP, etc create HTML dynamically at run-time, right?

    For a beginner like me, it would seem to make more sense to hard-code the HTML and CSS, and just use OOP (in my case PHP OOP) to write the back-end business logic.

    I mean I could use OOP to generate the "presentation layer" as well, but I am *hoping* that I can point my HTML code to my Classes/Objects.

    For example...

    I want to create a "Registration" class that handles creating a new Member.

    I was thinking maybe I could have a web-form where the user enters a "Username", "Password", and "First Name".

    Then, when the user clicks the "Create Account" button, my form webpage would somehow instantiate the "Registration" class - thus creating a new "Registration" object, which would in turn take the HRML form input, process it, and create a new Member.

    So, I would have a hard-coded HTML form that calls an OOP Class which does the back-end business logic.

    Does that make sense?



    Debbie

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default

    Some of your HTML can be hard coded, but as soon as you want to display something different depending on the user then you'll have to head down the JSP road, I'd say.

    Anyway, to take your starting example, try coding up the Registration stuff, since you seem to have the basic concepts down. You've already identified Registration (which maps to the HTML form), and Member, which maps to the registered person (possibly in a db?).

    Create those classes, and the persistence layer (the db), ignoring the fact it'll come from an HTML form. Get that working with some really basic data - a test involving creatng a Registration object, register the user (either by passing the Registration object into something else, or by having it capable of self registering), and check the returned Member.

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    First of all, yes, my English is not fluent as such. But I'll try to explain the best I can. And thanks for the help too. :)

    If you consider language like PHP, JS I've confidence that whatever you want, you can do it in OO base model. I'll explain one thing I've done to build a website, in PHP. Using AJAX calls basically the entire site front-end dynamically created. For each controls, such as list views, tab pages and so on, I've created separate JS classes and use them. Performance vise also it's well ahead than comparing to JSP and ASP.Net sites.

    Creating the back-end based on OO concepts is not a big deal to you I guess. Only thing it that you've clearly breakdown the steps that you are going to handle in different layers. Whatever the way you follow, try to avoid hard-coded stuff as much as possible. Those kind makes you lots of troubles in later.

  6. #6
    DoubleDee is offline Member
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    28
    Rep Power
    0

    Default

    Quote Originally Posted by Tolls View Post
    Some of your HTML can be hard coded, but as soon as you want to display something different depending on the user then you'll have to head down the JSP road, I'd say.
    *Having a hard time articulating this*

    I understand something dynamic like a Product Catalog needs to be dynamic, but what I meant was that I was uncertain if I had to have every line of HTML come from within a class.

    In theory, you could have different classes that create all of the HTML at run-time and thus no HTML files at all.

    To me, it seems silly to go to that extreme.

    Most of your website's structure will be static, right?

    I mean page layouts, headers, footers, search areas, columns contains popular links, etc. don't change much.

    So I was going to hard-code those things (e.g. Registration form) and then focus on having OO code in the background do the work.

    Follow me?


    Anyway, to take your starting example, try coding up the Registration stuff, since you seem to have the basic concepts down. You've already identified Registration (which maps to the HTML form), and Member, which maps to the registered person (possibly in a db?).

    Create those classes, and the persistence layer (the db), ignoring the fact it'll come from an HTML form. Get that working with some really basic data - a test involving creatng a Registration object, register the user (either by passing the Registration object into something else, or by having it capable of self registering), and check the returned Member.
    I can give that a try.

    Not sure what you mean by "persistence layer"?



    Debbie

  7. #7
    DoubleDee is offline Member
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    28
    Rep Power
    0

    Default

    Quote Originally Posted by Eranga View Post
    [COLOR="DarkGreen"]First of all, yes, my English is not fluent as such. But I'll try to explain the best I can. And thanks for the help too. :)
    Hey, my OOP is non-existence, so you are still one up on me! :)


    If you consider language like PHP, JS I've confidence that whatever you want, you can do it in OO base model.
    I would hope so!


    Creating the back-end based on OO concepts is not a big deal to you I guess.
    I think it will be easier than write some class to dynamically create HTML to display the home page.

    (Why write a class to create a static HTML page when you could just write a static HTML page alone?!) :confused:


    Only thing it that you've clearly breakdown the steps that you are going to handle in different layers. Whatever the way you follow, try to avoid hard-coded stuff as much as possible. Those kind makes you lots of troubles in later.
    I would not hard-code a Product Catalog or a Search Page, but why not hard-code parts of my website that will unlikely change?



    Debbie

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default

    Quote Originally Posted by DoubleDee View Post
    *Having a hard time articulating this*

    I understand something dynamic like a Product Catalog needs to be dynamic, but what I meant was that I was uncertain if I had to have every line of HTML come from within a class.

    In theory, you could have different classes that create all of the HTML at run-time and thus no HTML files at all.

    To me, it seems silly to go to that extreme.

    Most of your website's structure will be static, right?

    I mean page layouts, headers, footers, search areas, columns contains popular links, etc. don't change much.

    So I was going to hard-code those things (e.g. Registration form) and then focus on having OO code in the background do the work.

    Follow me?
    I follow you, and in most simple cases this is correct. However, in the "real" world, you'll find that stuff is actually rarely static, which is why even simple login pages tend to have dynamic elements...at some point something will change. But in your case I suspect static for at least the login will be fine.

    Quote Originally Posted by DoubleDee View Post
    I can give that a try.

    Not sure what you mean by "persistence layer"?

    Debbie
    You're already thinking in object terms, which is always a good start.

    As for "persistence layer", most systems are developed in terms of layers. You'd have a client layer (which would be, for example, the html and servlets).
    The servlets would interact with a business layer in which any "business" logic would be handled.
    The business layer would then interact with a persistence layer, which is the bit that stores any data that needs to be retrieved. That is it persists that data.
    Each of these layers (the business and persistence ones) are usually sets of interfaces, because the higher layers shouldn't care *how* it does the job, just that it does it. So, the business layer doesn't care how the data is persisted. Could be in a database, in a text file, or a call to another system entirely. Which is why it's called a persistence layer and not a database layer.

    That's OO, at least in java. Define interfaces for what things do, and code against those interfaces.

    I suspect that's a lot to take in...:)

  9. #9
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,436
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by DoubleDee View Post
    (Why write a class to create a static HTML page when you could just write a static HTML page alone?!) :confused:
    That's why they came up with JSPs; a JSP is html code with a couple of special tags and even (optionally) plain Java code. Internally a JSP is translated to just Java which handles all the html stuff for you. Minimally a JSP is just html code, 'over the top' a JSP is stuffed with all sorts of tags and Java code and tries to do everything and then some ...

    kind regards,

    Jos

  10. #10
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    For me it's more simple to write static HTML pages from the scratch as I mentioned. Basically because of the performance, relevant to page load time specifically.

  11. #11
    DoubleDee is offline Member
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    28
    Rep Power
    0

    Default

    Quote Originally Posted by Tolls View Post
    You're already thinking in object terms, which is always a good start.
    Definitely trying! :)


    As for "persistence layer", most systems are developed in terms of layers. You'd have a client layer (which would be, for example, the html and servlets).
    The servlets would interact with a business layer in which any "business" logic would be handled.
    The business layer would then interact with a persistence layer, which is the bit that stores any data that needs to be retrieved. That is it persists that data.
    Each of these layers (the business and persistence ones) are usually sets of interfaces, because the higher layers shouldn't care *how* it does the job, just that it does it. So, the business layer doesn't care how the data is persisted. Could be in a database, in a text file, or a call to another system entirely. Which is why it's called a persistence layer and not a database layer.
    So what are all of the different "layers" in Java? In OOP?


    That's OO, at least in java. Define interfaces for what things do, and code against those interfaces.

    I suspect that's a lot to take in...:)
    It is, but if you all stick with me, I'm sure I can learn this stuff! :o



    Debbie

  12. #12
    DoubleDee is offline Member
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    28
    Rep Power
    0

    Default

    Quote Originally Posted by Eranga View Post
    For me it's more simple to write static HTML pages from the scratch as I mentioned. Basically because of the performance, relevant to page load time specifically.
    Exactly. If a page doesn't change (e.g. my form won't be dynamic) then why bother with PHP or JSP?

    If your webpage is a "Product Details" page or a "Search Results" page, then that is a whole different discussion.

    Anyways, I should move on to my larger OOP questions...

    Should I ask them here or start a new thread?



    Debbie

  13. #13
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,436
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by DoubleDee View Post
    Exactly. If a page doesn't change (e.g. my form won't be dynamic) then why bother with PHP or JSP?
    If an html page definitely, positively, absolutely never changes there's no need to turn it into a JSP; simply leave it an html page.

    kind regards,

    Jos

  14. #14
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default

    Quote Originally Posted by DoubleDee View Post
    So what are all of the different "layers" in Java? In OOP?
    Layers aren't an OO thing.

    They're a way of breaking up responsibility of the code. They're a boundary between areas of code, so the View part (your HTML, and the controller bits likes servlets) will interact with your business layer via its interfaces. The view layer does not need to know exactly how the business stuff works, it only needs to know what the business layer needs to perform its job.

    The basic "layers" are a view, business and usually some persistence layer. Ther can be loads though, cine the persistence layer might interact with another system entirely, hence another layer or set of layers.

    So, one person can be working on the business code and someone else can be working on the gui code and, so long as the interface between them is defined (at least partially), they should be able to work almost in splendid isolation. Of course there will be changes as you work through, but hopefully these can be minimised by the breaking up of the requirements.

    At least that's the theory, and it seems to work in practice...

  15. #15
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,436
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Tolls View Post
    At least that's the theory, and it seems to work in practice...
    In theory: the layers on lower levels do not depend on layers in the upper levels. Upper level layers do depend on the lower level layers; in practice managerial decisions or just sloppy programming ruin this theoretical rule and you'll end up with a monolithic mess.

    kind regards,

    Jos

  16. #16
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default

    Only in so far as they depend on them fulfilling the contract of the interface, and that applies across the interface in both directions (the lower levels depend on the upper levels providing the required info).

    That should be the only dependency. Essentially the common interface, and common model for the things passed across that interface.

    But yes, as a project ages and requirements fluctuate and defects are raised and fixes are added then the concept can get a bit frayed around the edges...:)

  17. #17
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by DoubleDee View Post
    Should I ask them here or start a new thread?
    I don't think it's really necessary, unless you want to talk to something totally not related with the title.

  18. #18
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by JosAH View Post
    If an html page definitely, positively, absolutely never changes there's no need to turn it into a JSP; simply leave it an html page.

    kind regards,

    Jos
    Even in some cases, if the UI part is dynamic on the page I've construct the relevant HTML code in backend and draw in the client side using only few AJAX calls. It's faster and more dynamic.

    In my experience most of the stuff could implement in that way, only matter is the time it take. Because you've to define each and every HTML element there could be thousand of such depends on the page content you want to add. So in that sense for larger commercial applications it's not practical solution.

  19. #19
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    hard code static html, and then you can use all the oop you want in determining business logic/rules of log in

  20. #20
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

Page 1 of 2 12 LastLast

Similar Threads

  1. What do I need to use this website?
    By ZachVK in forum Java Applets
    Replies: 27
    Last Post: 06-24-2010, 08:15 PM
  2. Interacting with a website
    By eyeamchito in forum Advanced Java
    Replies: 7
    Last Post: 05-29-2010, 11:00 PM
  3. programming website?
    By ragarwal in forum Forum Lobby
    Replies: 11
    Last Post: 12-21-2009, 12:37 PM
  4. migrate JSP website
    By valhensing in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 12-14-2009, 03:34 PM
  5. How to download website (Get all link in website)
    By finalmem in forum Advanced Java
    Replies: 0
    Last Post: 11-12-2008, 08:43 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •