wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes OO  class design Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "OO  class design" Watch "OO  class design" New topic
Author

OO class design

Nicol Green
Ranch Hand

Joined: Jan 30, 2010
Posts: 66
Hi guys!

I have one more question about OO design. In my previous post "Class relations mass" I got great assistance from Pete Stein. Thank You Pete, once more for that. Here I have similar problem, and I don't know how to apply entirely suggested logic. I will appreciate help on this.

Now I have class View, where GUI is implemented.
I want to do caesar encryption, and a few more.
I was thinking to create Caesar class, Playfair, ..., Encryption class,
and View. Is this a good thinking, or do I need only Encryption class
and put all cipher implementations in that one ?
This is the Encryption class, but I am not sure how to define encryption, to
say so ? Could You, please, help me somehow ?



Thank You!
salvin francis
Ranch Hand

Joined: Jan 12, 2009
Posts: 928

First of all with MVC archiectecture, i suggest the following:



As an Optimization you might want to make Encryption's methods static ..


Next as you say you might change the encryption scheme later,

To this I suggest two approaches,

Approach 1 : Encryption contains type encryption Login.




Approach 2: Decorator-based Pattern

will post this idea soon.....

My Website: [Salvin.in] Cool your mind:[Salvin.in/painting] My Sally:[Salvin.in/sally]
salvin francis
Ranch Hand

Joined: Jan 12, 2009
Posts: 928

Approach 2 : Decorator-based Pattern



code can be written as :


This is not purely the decorator pattern though
Nicol Green
Ranch Hand

Joined: Jan 30, 2010
Posts: 66
Thank You very much for your help, Salvin!

Maybe I like a bit more second approach.
I will go with it!

This is not purely the decorator pattern though


Sorry, this is new concept for me. I google it, but haven't find much.
Could You, please, give me a short explanation of it ? After that I suppose
I will see why this is not a "purely decorator pattern".Thanks!
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

salvin francis wrote:As an Optimization you might want to make Encryption's methods static.

Whereas I would suggest you don't, since static methods can make testing more difficult, and any "optimization" you get is minimal at best.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: OO class design