Abstract Factory Design Pattern... troubles creating interface

From: Barry Hynes (base_at_islandtelecom.com)
Date: 06/23/04


Date: Wed, 23 Jun 2004 13:44:54 GMT

Good Day Folks,

I am trying to use an Abstract Factory to implement a program working with
file encryption.
i have 2 encryption algorithims...

1.) a positive integer N (0 < N < 128) is added to the ordinal value of each
character.
      The user supplies the encryption code N at runtime. (i called this
OrdEncryption)
2.) The user provides a keyword; an input file is divided into blocks equal
to the size of
      the key word, the ith character in that bl*** is encrypted by adding
the ASCII code
     of the ith character in the keyword.(called this KeyEncryption)

i'm pretty green in c++...doin a correspondence course...over my head!

having trouble on deciding what type of virtual function i should use...not
to sure on how to
find the file name and key/word at runtime

any help greatly appreciated

Barry

virtual void encrypt() const = 0;
virtual void encrypt(const string&, const string&) const = 0;

#ifndef ABSTRACTFILEOPS_H
#define ABSTRACTFILEOPS_H
  class AbstractFileOps { // abstract
  public:
    virtual void encrypt() const = 0; //abstract
    int doEncryption(const string&); //Template (concrete)
  protected:
   virtual ~AbstractFileOps();
  };
  #endif

#ifndef KEYENCRYPTION_H
#define KEYENCRYPTION_H
#include "abstractfileops.h"

  class KeyEncryption : public AbstractFileOps { // abstract
  public:
    virtual void encrypt() const = 0; //abstract
    KeyEncryption(const string&, const string&);
 ~KeyEncryption();
  private:
   mutable ifstream fileVar_;
  };
  #endif

#ifndef ORDENCRYPTION_H
#define ORDENCRYPTION_H
#include "abstractfileops.h"

  class OrdEncryption : public AbstractFileOps { // abstract
  public:
    virtual void encrypt() const = 0; //abstract
    OrdEncryption(const string&, const string&);
 ~OrdEncryption();
  private:
   mutable ifstream fileVar_;
  };
  #endif

#ifndef ABSTRACTAPPLICATION_H
#define ABSTRACTAPPLICATION_H

  class AbstractFileOps;
  class AbstractApplication { // abstract Factory
  public:
    virtual AbstractFileOps* factoryMethod() const = 0;
    void encrypt(const string&, const string&) const; //template method.
    virtual ~AbstractApplication();
  };
  #endif

#ifndef KEYENCRYPTIONAPPLICATION_H
#define KEYENCRYPTIONAPPLICATION_H
#include "abstractappilcation"

  class KeyEncryptionApplication : public AbstractApplication{ // implements
  public:
 KeyEncryptionApplication(const string&, const string &);
    ~KeyEncryptionApplication();
 virtual KeyEncryption* factoryMethod() const;
  private:
   string key_;
      string filename_;
   int keySize_;
  };
  #endif

#ifndef ORDENCRYPTIONAPPLICATION_H
#define ORDENCRYPTIONAPPLICATION_H
#include "abstractapplication.h"
  class OrdEncryptionApplication : public AbstractApplication{ // implements
  public:
 OrdEncryptionApplication(const string&, const string &);
    ~OrdEncryptionApplication();
 virtual OrdEncryption* factoryMethod() const;
  private:
   int ord_;
      string filename_;
  };
  #endif


Quantcast