Thank you for the proposals!

Feedback was sent!

~10% of final grade

Mike Chabot

Wednesday 3/11

Frontend, Backend, DevOps

Meaningful Names

Small Functions

Modular Functions

Function Arguments

Code Formatting

Comments

Object Oriented

Constructor

Instances / Instance Variables

Getters / Setters

Static Methods

Singleton Pattern

Singleton Pattern

same instances!

Restricts to only one instance of a class!

But why ?!

Singleton Pattern

Database

Logger

db = Database.getInstance();
db.search('something');
db = Database.getInstance();
db.add(new_product);
db = Database.getInstance();
db.delete(new_product);
Logger.print('User logged in.');
Logger.print('Product deleted.');
db = new Database();
db.search('something');
db = new Database();
db.add(new_product);
logger = new Logger();
logger.print('Product deleted.');
logger = new Logger();
logger.print('User logged in.');
class Circle:
    
    instance = None
    
    def __init__(self):
        '''
        Constructs a circle.
        '''
        self.__radius = 7 # this is private
        self.__radius2 = 1
        
        print('called constructor')
        
    def setRadius(self,radius):
        
        if radius == 7 or radius == 8:
        
            self.__radius = radius
        
    def getRadius(self):
        
        return self.__radius
        
    def getRadii(self):
        '''
        Returns a list of both values.
        '''
        return [self.__radius, self.__radius2]
        
    def draw(self):
        print('O'*self.radius)
        
    @staticmethod
    def create():
        
        if Circle.instance == None:
            Circle.instance = Circle()
            
        return Circle.instance
        
public final class Circle {

    private static final Circle INSTANCE = 
      new Circle();

    private Circle() {}

    public static Circle getInstance() {
        return INSTANCE;
    }
}

Lazy loading!

Hands-on Series!

Today: C++ Basics

3/13: C++ Functions and Classes

3/27: C++ Arrays and Vectors

4/3: C++ Templates

4/10: C++ and Python with Cython!

conda install xeus-cling -c conda-forge

CS410 Lecture 14

By Daniel Haehn

CS410 Lecture 14

Slides for CS410 Software Engineering at UMass Boston. See https://cs410.net!

  • 280

More from Daniel Haehn