aspose file tools*
The moose likes Beginning Java and the fly likes DAO without datase Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "DAO without datase" Watch "DAO without datase" New topic
Author

DAO without datase

Diego Macario
Greenhorn

Joined: Jul 26, 2012
Posts: 10
hi, it´s my firts post and i´m started to learn Java

I have a job for my college that i´ve done but i want to learn a new way to separte the things....

i need to make a note with contatcs and telephones but i didn´t found a way to make it with DAO pattern

i want to know if someone can help me to learn and understand

because every example that i find in google is with database, but i will persist this in a collection....

sorry for my english...

thanks
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 5288
    
  10

First, you need to understand the purpose of a Data Access Object, which I find even many experienced developers don't fully understand. It's actually good that you want to use a DAO to work with a collection instead of a database. This will probably help you understand the purpose of a DAO.

A DAO provides an abstraction. That is, it hides implementation details and gives you a more abstract way of thinking about how information about an object is stored. A properly designed DAO makes the fact that a collection or database is being used irrelevant. As far as the code that uses it is concerned, the DAO could be talking to a leprechaun who is writing everything down on Post-It notes stuck on a big corkboard.

Does this make sense so far? I'll follow up later; have to run out for a little bit.


Junilu - [How to Ask Questions] [How to Answer Questions]
Jelle Klap
Bartender

Joined: Mar 10, 2008
Posts: 1836
    
    7

Hi, and welcome to JavaRanch!

The DAO pattern is meant to encapsulate and abstract access to a data source; any data source. That data source could be a transient in-memory data source like a Collection, instead of a persistent data source like a database typically is. A DAO implementation that reads/writes to an in-memory data source is most commonly used as a test-double, though. If all you're going to do is keep your business objects in-memory, why do you feel the DAO pattern would be a good fit? Perhaps I'm misinterpreting your explanation, though. It would be helpful to know a bit more about the application's requirements.

Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Diego Macario
Greenhorn

Joined: Jul 26, 2012
Posts: 10
Thanks for all answer

I will explain my problem

I´ve done this work for my college but i started to study so much Java to learn other ways to program

My problem is, i need to do a note that stores contacts, each contact have 0..* telephones

I always thinks, can i make my code more simple to understand and more separated...

I make a class model telephone who stores in a map or any collection of that...

and put the methods to add, alter, delete, show and find...

but i thinks its can be put in other class...

i saw i video in youtube and i have a little idea for DAO...

wich separate in 3 layers...


model who have only attributes and geters and setters of class

dao who intermediate vision class and controller class

controler who have methods to persisti in a class

i´m wrong?

thanks to all helping
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 5288
    
  10

DAO - responsible for persistence concerns

Controller - acts as an intermediary between View and Model/Business classes.
Diego Macario
Greenhorn

Joined: Jul 26, 2012
Posts: 10
Junilu Lacar wrote:DAO - responsible for persistence concerns

Controller - acts as an intermediary between View and Model/Business classes.



i forgot to say 2 things

i´m not using GUI and i´ve started to learn 5 months ago Java

my doubts are about

modeling classes

i need to make 3 DAO classes and 3 conttrolers

or its depends of the objective of my program

how can you help me?

thanks
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 5288
    
  10

Diego Macario wrote:
how can you help me?

By explaining some things to you, pointing you to material that you can read to get better understanding, and looking at your code to see if we have suggestions on how to make it better. Other than that, we won't do your work for you, but you probably already realize that.

As Jelle said, it would help if you explain a little bit more what your requirements are, why you think you need DAOs and Controllers, etc. It would also help if you showed us some of the code you have written so far, if any. Just code snippets, please -- don't post 500 lines of code, or even 100 lines. Thanks.
Diego Macario
Greenhorn

Joined: Jul 26, 2012
Posts: 10
Junilu Lacar wrote:
Diego Macario wrote:
how can you help me?

By explaining some things to you, pointing you to material that you can read to get better understanding, and looking at your code to see if we have suggestions on how to make it better. Other than that, we won't do your work for you, but you probably already realize that.

As Jelle said, it would help if you explain a little bit more what your requirements are, why you think you need DAOs and Controllers, etc. It would also help if you showed us some of the code you have written so far, if any. Just code snippets, please -- don't post 500 lines of code, or even 100 lines. Thanks.


of course i know that you wont do my job and in this way i´m not going to learn

i´m going to put my class

package model - class telephone



package persistence - class telephoneDAO



package control - class telephonecontroler




My code have some methods in portuguese because i´m from Brazil....

But i have a doubt...where i put the collection to persiste de date because every time i make a new action i instance a new class and create a new object collection

My code have some erros, because i need to correct...

But i will correct this...

I did this...
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 5288
    
  10

What is this date and what is its relation to Telephone? Your code actually looks pretty decent, not too bad for someone who only learned Java in the last 5 months. I've seen worse from supposedly more experienced programmers.
Diego Macario
Greenhorn

Joined: Jul 26, 2012
Posts: 10
Junilu Lacar wrote:What is this date and what is its relation to Telephone?


Sorry but i need to pratice more my english to show what i´m telling

Thats, i dont know where to put the hahsmap to work like a database...

Do you understand?

Junilu Lacar wrote:Your code actually looks pretty decent, not too bad for someone who only learned Java in the last 5 months. I've seen worse from supposedly more experienced programmers.


thanks 4 your words but i need to improve my code, i´m reading some books like refactoring, pragmatic programmer, how to program java, head first Java

but i get off my code and now i´m going to post all....

class model



class telephoneControler



DAO telephone class



class that interate with user

class IUTelephone




thats all i have, i didnt put my exception class to not full this page...

thanks
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 5288
    
  10

In your case, the DAO is probably the best place for you to keep the data structure in which you will "persist" your objects. Declare the HashMap as a private member of your DAO class. Note that keeping them in memory is not really persisting the objects. Persistence means that you can get the objects back after you terminate the program and run it again. An in-memory solution is not true persistence.
Diego Macario
Greenhorn

Joined: Jul 26, 2012
Posts: 10
Junilu Lacar wrote:In your case, the DAO is probably the best place for you to keep the data structure in which you will "persist" your objects. Declare the HashMap as a private member of your DAO class. Note that keeping them in memory is not really persisting the objects. Persistence means that you can get the objects back after you terminate the program and run it again. An in-memory solution is not true persistence.



hehehe, i know this...my teache told me...

i´ll make my code e later i post it

thanks a lot
Diego Macario
Greenhorn

Joined: Jul 26, 2012
Posts: 10
I have ended my job...now i want to know if its good

class exception





class input user



class model



class controler



class DAO



So i know this code is very extensive but if its good someone can use....

I didnt put menu and main class....

Say if something is wrong

Thanks
Diego Macario
Greenhorn

Joined: Jul 26, 2012
Posts: 10
anyone wants to help me?
jasonhu hu
Greenhorn

Joined: Aug 01, 2012
Posts: 6
i come from China,hope we can help each other
Diego Macario
Greenhorn

Joined: Jul 26, 2012
Posts: 10
hey, do you have the same problem as me?

thanks
 
Don't get me started about those stupid light bulbs.
 
subject: DAO without datase