Skip to main content
added 232 characters in body
Source Link

Usually on Php or in Java and in other single Inheritance Object Oriented Languages, when I am writing a software I use and Interface then and afterwards I implement the class that implements the business logic.

For example let us suppose we have a File Uploader that allow us to Upload into various ways in our case into an FtpServer or into an AmazonS3 Bucket.

Therefore I declare an interface FileUploaderInterface

interface FileUploaderInterface 
{
   public function addFile(fromPath,toPath);
   public function removeFile(path);
}

And afterwards I Implement a seperate fileUploader for each seperate way we want to upload the data:

eg. for Ftp

class FtpFileUploader implements  FileUploaderInterface
{
   public function addFile(fromPath,toPath)
   {
     //Implement Method
   }
   public function removeFile(path)
   {
     //Implement Method
   }
}

eg. And for Amazon S3

class AmazonS3FileUploader implements FileUploaderInterface
{
   public function addFile(fromPath,toPath)
   {
     //Implement Method
   }
   public function removeFile(path)
   {
     //Implement Method
   }
}

With that I have the flexibility to have a Unique Handling for the file uploads regardless how the Upload Mechanism itself will work so if I want to upload using an X api I just have to implement the FileUploaderInterface Interface.

But on ES6 I find a it myself like a fish out of water int terms of software desighn so it it a good idea/practice to declare a class that has all the basic methods it want that plays the role of an interface

eg: A generic class for file Uploading in a file named 'FileUploader.js'

export default class FileManager {

  addFile(fromPath,toPath,callback){

  }


  deleteFile(path, callback){

  }
 }

And for each way for uploading I just develop a specific class:

eg. For Uploading via FTP

import FileManager from './FileUploader.js'

export default class FtpUploadManager extends FileManager {

  addFile(fromPath,toPath,callback){
    // Implement method
  }


  deleteFile(path, callback){
    // Implement method
  }
}

eg. For uploading via Amazon S3

import FileManager from './FileUploader.js'

export default class S3UploadManager extends FileManager {

  addFile(fromPath,toPath,callback){
    // Implement method
  }


  deleteFile(path, callback){
    // Implement method
  }
}

What are the pos and cons of using the following method? Please

The main difference I need some tips!am asking of Are there any OO-principles that are practically applicable for Javascript? is if a specific way of using Js Classes is good or not and not a generic one.

Usually on Php or in Java and in other single Inheritance Object Oriented Languages, when I am writing a software I use and Interface then and afterwards I implement the class that implements the business logic.

For example let us suppose we have a File Uploader that allow us to Upload into various ways in our case into an FtpServer or into an AmazonS3 Bucket.

Therefore I declare an interface FileUploaderInterface

interface FileUploaderInterface 
{
   public function addFile(fromPath,toPath);
   public function removeFile(path);
}

And afterwards I Implement a seperate fileUploader for each seperate way we want to upload the data:

eg. for Ftp

class FtpFileUploader implements  FileUploaderInterface
{
   public function addFile(fromPath,toPath)
   {
     //Implement Method
   }
   public function removeFile(path)
   {
     //Implement Method
   }
}

eg. And for Amazon S3

class AmazonS3FileUploader implements FileUploaderInterface
{
   public function addFile(fromPath,toPath)
   {
     //Implement Method
   }
   public function removeFile(path)
   {
     //Implement Method
   }
}

With that I have the flexibility to have a Unique Handling for the file uploads regardless how the Upload Mechanism itself will work so if I want to upload using an X api I just have to implement the FileUploaderInterface Interface.

But on ES6 I find a it myself like a fish out of water int terms of software desighn so it it a good idea/practice to declare a class that has all the basic methods it want that plays the role of an interface

eg: A generic class for file Uploading in a file named 'FileUploader.js'

export default class FileManager {

  addFile(fromPath,toPath,callback){

  }


  deleteFile(path, callback){

  }
 }

And for each way for uploading I just develop a specific class:

eg. For Uploading via FTP

import FileManager from './FileUploader.js'

export default class FtpUploadManager extends FileManager {

  addFile(fromPath,toPath,callback){
    // Implement method
  }


  deleteFile(path, callback){
    // Implement method
  }
}

eg. For uploading via Amazon S3

import FileManager from './FileUploader.js'

export default class S3UploadManager extends FileManager {

  addFile(fromPath,toPath,callback){
    // Implement method
  }


  deleteFile(path, callback){
    // Implement method
  }
}

What are the pos and cons of using the following method? Please I need some tips!

Usually on Php or in Java and in other single Inheritance Object Oriented Languages, when I am writing a software I use and Interface then and afterwards I implement the class that implements the business logic.

For example let us suppose we have a File Uploader that allow us to Upload into various ways in our case into an FtpServer or into an AmazonS3 Bucket.

Therefore I declare an interface FileUploaderInterface

interface FileUploaderInterface 
{
   public function addFile(fromPath,toPath);
   public function removeFile(path);
}

And afterwards I Implement a seperate fileUploader for each seperate way we want to upload the data:

eg. for Ftp

class FtpFileUploader implements  FileUploaderInterface
{
   public function addFile(fromPath,toPath)
   {
     //Implement Method
   }
   public function removeFile(path)
   {
     //Implement Method
   }
}

eg. And for Amazon S3

class AmazonS3FileUploader implements FileUploaderInterface
{
   public function addFile(fromPath,toPath)
   {
     //Implement Method
   }
   public function removeFile(path)
   {
     //Implement Method
   }
}

With that I have the flexibility to have a Unique Handling for the file uploads regardless how the Upload Mechanism itself will work so if I want to upload using an X api I just have to implement the FileUploaderInterface Interface.

But on ES6 I find a it myself like a fish out of water int terms of software desighn so it it a good idea/practice to declare a class that has all the basic methods it want that plays the role of an interface

eg: A generic class for file Uploading in a file named 'FileUploader.js'

export default class FileManager {

  addFile(fromPath,toPath,callback){

  }


  deleteFile(path, callback){

  }
 }

And for each way for uploading I just develop a specific class:

eg. For Uploading via FTP

import FileManager from './FileUploader.js'

export default class FtpUploadManager extends FileManager {

  addFile(fromPath,toPath,callback){
    // Implement method
  }


  deleteFile(path, callback){
    // Implement method
  }
}

eg. For uploading via Amazon S3

import FileManager from './FileUploader.js'

export default class S3UploadManager extends FileManager {

  addFile(fromPath,toPath,callback){
    // Implement method
  }


  deleteFile(path, callback){
    // Implement method
  }
}

What are the pos and cons of using the following method?

The main difference I am asking of Are there any OO-principles that are practically applicable for Javascript? is if a specific way of using Js Classes is good or not and not a generic one.

Source Link

ES6 and OO Desighn: It is good idea to use a class as "Interface"?

Usually on Php or in Java and in other single Inheritance Object Oriented Languages, when I am writing a software I use and Interface then and afterwards I implement the class that implements the business logic.

For example let us suppose we have a File Uploader that allow us to Upload into various ways in our case into an FtpServer or into an AmazonS3 Bucket.

Therefore I declare an interface FileUploaderInterface

interface FileUploaderInterface 
{
   public function addFile(fromPath,toPath);
   public function removeFile(path);
}

And afterwards I Implement a seperate fileUploader for each seperate way we want to upload the data:

eg. for Ftp

class FtpFileUploader implements  FileUploaderInterface
{
   public function addFile(fromPath,toPath)
   {
     //Implement Method
   }
   public function removeFile(path)
   {
     //Implement Method
   }
}

eg. And for Amazon S3

class AmazonS3FileUploader implements FileUploaderInterface
{
   public function addFile(fromPath,toPath)
   {
     //Implement Method
   }
   public function removeFile(path)
   {
     //Implement Method
   }
}

With that I have the flexibility to have a Unique Handling for the file uploads regardless how the Upload Mechanism itself will work so if I want to upload using an X api I just have to implement the FileUploaderInterface Interface.

But on ES6 I find a it myself like a fish out of water int terms of software desighn so it it a good idea/practice to declare a class that has all the basic methods it want that plays the role of an interface

eg: A generic class for file Uploading in a file named 'FileUploader.js'

export default class FileManager {

  addFile(fromPath,toPath,callback){

  }


  deleteFile(path, callback){

  }
 }

And for each way for uploading I just develop a specific class:

eg. For Uploading via FTP

import FileManager from './FileUploader.js'

export default class FtpUploadManager extends FileManager {

  addFile(fromPath,toPath,callback){
    // Implement method
  }


  deleteFile(path, callback){
    // Implement method
  }
}

eg. For uploading via Amazon S3

import FileManager from './FileUploader.js'

export default class S3UploadManager extends FileManager {

  addFile(fromPath,toPath,callback){
    // Implement method
  }


  deleteFile(path, callback){
    // Implement method
  }
}

What are the pos and cons of using the following method? Please I need some tips!