Question

Swift code import Foundation protocol TaksPerformer { func doAThing() } class Employee: TaksPerformer { let name: String...

Swift code

import Foundation

protocol TaksPerformer {

func doAThing()

}

class Employee: TaksPerformer {

let name: String

var boss: Boss?

init(name: String) {

self.name = name

}

func doAThing() {

print("\(name) is doing a thing")

}

}

class Boss {

var employee: Employee

let name: String

init(name: String, employee: Employee) {

self.name = name

self.employee = employee

employee.boss = self

}

func actLikeABoss() {

employee.doAThing()

}

}

// 1)

// A) What is wrong with the current implementation of Boss and Employee, why is it wrong, and how can we demonstrate that there is an issue?

//

// B) What pattern discussed in class does the Boss - Employee relationship remind you of? Give an example of the discussed pattern.

//

// C) Create a Person class that has the following property:

// let name: String

// Now have Employee and Boss inherit from Person

//

// D) You realize that there are speciffic tasks you would like an employee to perform. All tasks look like this:

// func makeCoffe(_ name: String) {

// print("\(name) made coffe")

// }

//

// func writeReport(_ name: String) {

// print("\(name) wrote a report")

// }

// Modify Boss, Employee and TaskPerformer in a way that a Boss can be instantiated with the following constructor:

// Boss(name: "Bossman", employee: anEmployee, tasks: [makeCoffe, writeReport])

// The employee instance should perform the tasks.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Swift code

1. A) In this above code cannot inheriting Employee class because Boss class trying to assign employee details to local variaEngine duetEngine new Engine( duetEngine.stop () C) var name n func Person (name: String) l this.name name func show Name ()b1.show Name () e1.show Name () var namel func Person (name1: String) this.name1 name1 func show Name () print (name1) func

Add a comment
Know the answer?
Add Answer to:
Swift code import Foundation protocol TaksPerformer { func doAThing() } class Employee: TaksPerformer { let name: String...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • please look at below code and respond all the required import Foundation protocol TaksPerformer { func doAThing() } clas...

    please look at below code and respond all the required import Foundation protocol TaksPerformer { func doAThing() } class Employee: TaksPerformer { let name: String var boss: Boss? init(name: String) { self.name = name } func doAThing() { print("\(name) is doing a thing") } } class Boss { var employee: Employee let name: String init(name: String, employee: Employee) { self.name = name self.employee = employee employee.boss = self } func actLikeABoss() { employee.doAThing() } } // 1) // A) What...

  • Write Java code with JDBC (as discussed in class) to perform the following tasks: EMPLOYEE(Name, Ssn,...

    Write Java code with JDBC (as discussed in class) to perform the following tasks: EMPLOYEE(Name, Ssn, Address, DeptNo, Age, Salary) DEPARTMENT(Dname, Dnumber, Budget, Mgr_ssn) Establish a logical session with a database you have created for the two relations Use JDBC to submit an SQL query and print the name of each employee with a salary greater than 100,000

  • Using the following code: store.py from abc import ABC,abstractmethod class Store(ABC): #creating a abstract class name=''...

    Using the following code: store.py from abc import ABC,abstractmethod class Store(ABC): #creating a abstract class name='' #declaring attributes in class address='' status='' sales_tax_percentage=0.0 def __init__(self,name,address,status,sales_tax_percentage): #init method to initialize the class attributes self.name=name self.address=address self.status=status self.sales_tax_percentage=sales_tax_percentage def get_name(self): #Getter and setter methods for variables return self.name def set_name(self,name): self.name=name def get_address(self): return self.address def set_address(self,address): self.address=address def set_status(self,status): self.status=status def get_status(self): return self.status def set_sales_tax_percentage(self,sales_tax_percentage): self.sales_tax_percentage=sales_tax_percentage def get_sales_tax_percentage(self): return self.sales_tax_percentage def is_store_open(self): #check store status or availability if self.status=="open": #Return...

  • //*Manager.java*// public interface Manager { public void handleCrisis(); } _________________________________________________________ /**Employee.java**/ Public abstract class Employee {...

    //*Manager.java*// public interface Manager { public void handleCrisis(); } _________________________________________________________ /**Employee.java**/ Public abstract class Employee { protected final String name; protected final int id; public Employee(String empName, int empId) { name = empName; id = empId; } public Employee() { name = generatedNames[lastGeneratedId]; id = lastGeneratedId++; } public String getName() { return name; } public int getId() { return id; } //returns true if work was successful. otherwise returns false (crisis) public abstract boolean work(); public String toString() { return...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT